Post

Replies

Boosts

Views

Activity

How can I view the Development-server private data for my iCloud test account in the CloudKit Dashboard?
When developing a CloudKit application, the standard recommendation is to create an iCloud account for testing. That makes a lot of sense as I’d like to keep developing code far from my personal iCloud account. But the CloudKit Dashboard won’t let me view the private database for that account. What do other people do to check their work?* clarification: I mean on the development server, not the production server.
3
0
1.7k
Dec ’22
Define Array of protocol which conforms to Identifiable
I've got Yet Another Protocol Question. Sorry, folks.The Swift 5.1 manual describes creating a `Collection` where the `Element` is a simple protocol, but doesn't explain how to make a Collection where the Element is a protocol with an associatedtype. In my case it's a protocol `Playable` that requires conformance to `Identifiable`.I am fine with requiring the `Identifiable.ID` type to be `Int` for all types which adopt `Playable`, but I don't know how to express that qualification/requirement. The bits hit the fan when I try to declare something to be `[Playable]`.My playground code might make my question clear.protocol Playable: Identifiable // DOESN'T WORK where ID: Int { // DOESN'T HELP associatedtype ID = Int // DOESN'T HELP var id: Int { get } func play() } struct Music: Playable { var id: Int func play() { print("playing music #\(id)") } } (Music(id: 1)).play() // displays: "playing music #1\n" class Game: Playable { var id: Int init(id: Int) { self.id = id } func play() { print("playing game #\(id)") } } (Game(id: 2)).play() // displays: "playing game #2\n" enum Lottery: Int, Playable { case state = 100 case church case charity var id: Int { return self.rawValue } func play() { print("playing lottery \(self) #\(self.rawValue)") } } Lottery.church.play() // displays: "playing lottery church #101\n" var stuff: [Playable] = [] // error: Protocol 'Playable' can only be used as a generic constraint because it has Self or associated type requirements stuff.append(Music(id: 10)) stuff.append(Game(id: 24)) stuff.append(Lottery.charity) stuff.map { $0.id }My goal is to have different structs and classes conforming to Playable (and hence to Identifiable) able to live inside a Collection.
7
1
7.7k
Nov ’22
(Xcode 14.0 beta 5) ThreadSanitizer: CHECK failed: tsan_platform_posix.cpp:83 "((beg)) <= ((end))"
Similarly to this old post [https://developer.apple.com/forums/thread/130969] I am getting a "ThreadSanitizer: CHECK failed" before my code seems to have launched. Is this something I should spend time trying to reproduce in a small project or is it an Xcode bug others are getting too? Turning off the sanitizer is my dirty workaround for now.
2
0
3k
Aug ’22
Laying out a table in SwiftUI
I want to present a table using SwiftUI. I've gotten most of the way using LazyVGrid. Problem 1 is the last row's frame paints below the LazyVGrid frame when the last cell is taller than the others. Problem 2 is the last column shows multiline text. All cells on that row should be aligned using VerticalAlignment.firstTextbaseline. What happens is all of the cells end up vertically aligned. private var columns: [GridItem] = [ GridItem(.fixed(25)), GridItem(.fixed(25)), GridItem(.fixed(30), alignment: .trailing), GridItem(.flexible()) ] var body: some View { LazyVGrid(columns: columns, alignment: .leading) { ForEach(rows) { row in Text(row.a) Text("#\(row.b)") Text("(\(row.c))") Text(row.d) .multilineTextAlignment(.leading) .lineLimit(nil) } } } I explored using custom alignment guides istead of LazyVGrid, but I don't know how to apply more than one guide to achieve the effect of tab stops for each column.
1
0
1.6k
May ’22
Xcode 13 suddenly using old frameworks
I've been building my app on Xcode 13 when suddenly it doesn't know about the iOS 15 APIs. Here are a couple error examples: self.modified = Date.now // Type 'Date' has no member 'now' and operation.modifySubscriptionsResultBlock = { result in // Value of type 'CKModifySubscriptionsOperation' has no member 'modifySubscriptionsResultBlock' I can take the exact same code and build it on my other Mac and it builds properly. Both Macs are using Xcode Version 13.0 (13A233) and running macOS 11.6 (20G165). I checked the deployment info for project and target (iOS 15.0), but of course using git I know I have the exact same code base on both machines. Is there an Xcode preference or system file that got hosed? I tried reinstalling Xcode, but it didn't help.
1
0
1.1k
Sep ’21
Attempt to map database failed
This looks like a refresh of an old question. I'm using iOS 15 beta 7 and have presented a UIActivityViewController from a SwiftUI app. I get a ton of these errors when trying to share a two-item list containing String and UISimpleTextPrintFormatter. [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} [default] Attempt to map database failed: permission was denied. This attempt will not be retried. [db] Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} [default] -imageForImageDescriptor: can do IO please adopt -imageForDescriptor: for IO free drawing or -prepareImageForDescriptor: if IO is allowed. (This will become a fault soon.) [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} It looks as if the API is checking for entitlements I haven't requested, but I am not trying to share images. I just want to share text as plaintext or a nicely formatted printable attributed string.
4
3
7.7k
Aug ’21
How to implement custom type for onDrag and onInsert
To implement row reordering I know I could use List{ForEach{}.onMove} but in my situation I can't use List for reasons. So I need to implement my own item reordering using onDrag and onInsert. These modifiers use NSItemProvider. I think therefore my dragged data type needs to implement NSItemProviderWriting (and NSItemProviderReading). I've looked for examples but the closest code I've found is dragging URLs. When I try to implement these protocols in my type I end up with an error in .onInsert at (NSItemProvider item).loadObject(ofClass:MyType.self) that says "Instance method 'loadObject(ofClass:completionHandler:)' requires that 'MyType' conform to '_ObjectiveCBridgeable'" How should I be using .onDrag and .onInsert with a custom type?
1
0
2.2k
Aug ’21
Dragging list rows between sections
I am making an iPhone-first app which has a 2 level data structure. I want the user to be able to drag List rows from section to section, but not reorder the sections. Is there a SwiftUI way to do it, or should I resort to UIKit? The basic problem seems to be that ForEach.onMove only allows reordering within its nearest datasource. That seems sensible as a general facility. As it stands now drags can only happen within a section. Swift ForEach(groups) { group in Section(header: Text(group.text)) { ForEach(group.items) { item in Text(item.text) } } } .onMove { … } I might be willing to dive into UIKit to get this done, if it'll handle it. Right now I've flattened the data and marked some items as "containers" and others as "leaves". All get emitted as a dumb flat list: Swift ForEach(items) { item in if item.isContainer { Text(item.text).bold() } else { Text(item.text) } } .onMove { … } The major downside is users can move the container "section header" lines. Drag and drop doesn't seem to work on iPhone, just iPads. I'm kinda shy about hierarchical lists using List(_,children:) because I expect move would still allow top level items (my containers) would be allowed to be moved.
4
0
5.7k
Jul ’21
Why does .swipeAction set editMode?
Why does a swipe action (using the new .swipeAction in SwiftUI 5.5, currently beta 3) set editMode? Notice when you swipe that "Edit" changes to "Done"? And yet this is not like full edit mode because tapping the EditButton shows the move handles (and the ever-annoying ugly blank indentation for the absent onDelete modifier). I think my next project won't use SwiftUI. import SwiftUI struct Fruit: Identifiable {     let id: UUID = UUID()     let name: String     let color: Color } struct ListingView: View {     @State var fruits: [Fruit] = [         Fruit(name: "banana", color: .yellow),         Fruit(name: "apple", color: .green),         Fruit(name: "tomato", color: .red)]          @Environment(\.editMode) private var editMode          var body: some View {         NavigationView {             VStack(alignment: .leading) {                 List {                     ForEach(fruits) { fruit in                         NavigationLink(                             destination: ZStack {                                 fruit.color                                 Text(fruit.name).bold().font(.largeTitle)                             }                                 .navigationTitle(fruit.name),                             label: {                                 HStack(alignment: .center) {                                     fruit.color.frame(width: 30, height: 30)                                     Text(fruit.name)                                 }                             })                             .swipeActions(edge: .leading, allowsFullSwipe: false) {                                 Button(action: { delete(fruit) },                                        label: { Image(systemName: "trash") }).tint(.red)                             }                     }                     .onMove(perform: { from, to in                         fruits.move(fromOffsets: from, toOffset: to)                     })                 }             }             .navigationBarTitle("Fruits")             .toolbar {                 ToolbarItem(placement: .primaryAction) {                     EditButton()                 }             }         }     }     private func delete(_ fruit: Fruit) {         guard let index = fruits.firstIndex(where: {$0.id == fruit.id}) else { return }         fruits.remove(at: index)     } } struct ListingView_Previews: PreviewProvider {     static var previews: some View {         ListingView()     } }
1
0
2.1k
Jul ’21
How can I view the Development-server private data for my iCloud test account in the CloudKit Dashboard?
When developing a CloudKit application, the standard recommendation is to create an iCloud account for testing. That makes a lot of sense as I’d like to keep developing code far from my personal iCloud account. But the CloudKit Dashboard won’t let me view the private database for that account. What do other people do to check their work?* clarification: I mean on the development server, not the production server.
Replies
3
Boosts
0
Views
1.7k
Activity
Dec ’22
Define Array of protocol which conforms to Identifiable
I've got Yet Another Protocol Question. Sorry, folks.The Swift 5.1 manual describes creating a `Collection` where the `Element` is a simple protocol, but doesn't explain how to make a Collection where the Element is a protocol with an associatedtype. In my case it's a protocol `Playable` that requires conformance to `Identifiable`.I am fine with requiring the `Identifiable.ID` type to be `Int` for all types which adopt `Playable`, but I don't know how to express that qualification/requirement. The bits hit the fan when I try to declare something to be `[Playable]`.My playground code might make my question clear.protocol Playable: Identifiable // DOESN'T WORK where ID: Int { // DOESN'T HELP associatedtype ID = Int // DOESN'T HELP var id: Int { get } func play() } struct Music: Playable { var id: Int func play() { print("playing music #\(id)") } } (Music(id: 1)).play() // displays: "playing music #1\n" class Game: Playable { var id: Int init(id: Int) { self.id = id } func play() { print("playing game #\(id)") } } (Game(id: 2)).play() // displays: "playing game #2\n" enum Lottery: Int, Playable { case state = 100 case church case charity var id: Int { return self.rawValue } func play() { print("playing lottery \(self) #\(self.rawValue)") } } Lottery.church.play() // displays: "playing lottery church #101\n" var stuff: [Playable] = [] // error: Protocol 'Playable' can only be used as a generic constraint because it has Self or associated type requirements stuff.append(Music(id: 10)) stuff.append(Game(id: 24)) stuff.append(Lottery.charity) stuff.map { $0.id }My goal is to have different structs and classes conforming to Playable (and hence to Identifiable) able to live inside a Collection.
Replies
7
Boosts
1
Views
7.7k
Activity
Nov ’22
(Xcode 14.0 beta 5) ThreadSanitizer: CHECK failed: tsan_platform_posix.cpp:83 "((beg)) <= ((end))"
Similarly to this old post [https://developer.apple.com/forums/thread/130969] I am getting a "ThreadSanitizer: CHECK failed" before my code seems to have launched. Is this something I should spend time trying to reproduce in a small project or is it an Xcode bug others are getting too? Turning off the sanitizer is my dirty workaround for now.
Replies
2
Boosts
0
Views
3k
Activity
Aug ’22
Laying out a table in SwiftUI
I want to present a table using SwiftUI. I've gotten most of the way using LazyVGrid. Problem 1 is the last row's frame paints below the LazyVGrid frame when the last cell is taller than the others. Problem 2 is the last column shows multiline text. All cells on that row should be aligned using VerticalAlignment.firstTextbaseline. What happens is all of the cells end up vertically aligned. private var columns: [GridItem] = [ GridItem(.fixed(25)), GridItem(.fixed(25)), GridItem(.fixed(30), alignment: .trailing), GridItem(.flexible()) ] var body: some View { LazyVGrid(columns: columns, alignment: .leading) { ForEach(rows) { row in Text(row.a) Text("#\(row.b)") Text("(\(row.c))") Text(row.d) .multilineTextAlignment(.leading) .lineLimit(nil) } } } I explored using custom alignment guides istead of LazyVGrid, but I don't know how to apply more than one guide to achieve the effect of tab stops for each column.
Replies
1
Boosts
0
Views
1.6k
Activity
May ’22
Xcode 13 suddenly using old frameworks
I've been building my app on Xcode 13 when suddenly it doesn't know about the iOS 15 APIs. Here are a couple error examples: self.modified = Date.now // Type 'Date' has no member 'now' and operation.modifySubscriptionsResultBlock = { result in // Value of type 'CKModifySubscriptionsOperation' has no member 'modifySubscriptionsResultBlock' I can take the exact same code and build it on my other Mac and it builds properly. Both Macs are using Xcode Version 13.0 (13A233) and running macOS 11.6 (20G165). I checked the deployment info for project and target (iOS 15.0), but of course using git I know I have the exact same code base on both machines. Is there an Xcode preference or system file that got hosed? I tried reinstalling Xcode, but it didn't help.
Replies
1
Boosts
0
Views
1.1k
Activity
Sep ’21
Attempt to map database failed
This looks like a refresh of an old question. I'm using iOS 15 beta 7 and have presented a UIActivityViewController from a SwiftUI app. I get a ton of these errors when trying to share a two-item list containing String and UISimpleTextPrintFormatter. [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} [default] Attempt to map database failed: permission was denied. This attempt will not be retried. [db] Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} [default] -imageForImageDescriptor: can do IO please adopt -imageForDescriptor: for IO free drawing or -prepareImageForDescriptor: if IO is allowed. (This will become a fault soon.) [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} It looks as if the API is checking for entitlements I haven't requested, but I am not trying to share images. I just want to share text as plaintext or a nicely formatted printable attributed string.
Replies
4
Boosts
3
Views
7.7k
Activity
Aug ’21
How to implement custom type for onDrag and onInsert
To implement row reordering I know I could use List{ForEach{}.onMove} but in my situation I can't use List for reasons. So I need to implement my own item reordering using onDrag and onInsert. These modifiers use NSItemProvider. I think therefore my dragged data type needs to implement NSItemProviderWriting (and NSItemProviderReading). I've looked for examples but the closest code I've found is dragging URLs. When I try to implement these protocols in my type I end up with an error in .onInsert at (NSItemProvider item).loadObject(ofClass:MyType.self) that says "Instance method 'loadObject(ofClass:completionHandler:)' requires that 'MyType' conform to '_ObjectiveCBridgeable'" How should I be using .onDrag and .onInsert with a custom type?
Replies
1
Boosts
0
Views
2.2k
Activity
Aug ’21
Dragging list rows between sections
I am making an iPhone-first app which has a 2 level data structure. I want the user to be able to drag List rows from section to section, but not reorder the sections. Is there a SwiftUI way to do it, or should I resort to UIKit? The basic problem seems to be that ForEach.onMove only allows reordering within its nearest datasource. That seems sensible as a general facility. As it stands now drags can only happen within a section. Swift ForEach(groups) { group in Section(header: Text(group.text)) { ForEach(group.items) { item in Text(item.text) } } } .onMove { … } I might be willing to dive into UIKit to get this done, if it'll handle it. Right now I've flattened the data and marked some items as "containers" and others as "leaves". All get emitted as a dumb flat list: Swift ForEach(items) { item in if item.isContainer { Text(item.text).bold() } else { Text(item.text) } } .onMove { … } The major downside is users can move the container "section header" lines. Drag and drop doesn't seem to work on iPhone, just iPads. I'm kinda shy about hierarchical lists using List(_,children:) because I expect move would still allow top level items (my containers) would be allowed to be moved.
Replies
4
Boosts
0
Views
5.7k
Activity
Jul ’21
Why does .swipeAction set editMode?
Why does a swipe action (using the new .swipeAction in SwiftUI 5.5, currently beta 3) set editMode? Notice when you swipe that "Edit" changes to "Done"? And yet this is not like full edit mode because tapping the EditButton shows the move handles (and the ever-annoying ugly blank indentation for the absent onDelete modifier). I think my next project won't use SwiftUI. import SwiftUI struct Fruit: Identifiable {     let id: UUID = UUID()     let name: String     let color: Color } struct ListingView: View {     @State var fruits: [Fruit] = [         Fruit(name: "banana", color: .yellow),         Fruit(name: "apple", color: .green),         Fruit(name: "tomato", color: .red)]          @Environment(\.editMode) private var editMode          var body: some View {         NavigationView {             VStack(alignment: .leading) {                 List {                     ForEach(fruits) { fruit in                         NavigationLink(                             destination: ZStack {                                 fruit.color                                 Text(fruit.name).bold().font(.largeTitle)                             }                                 .navigationTitle(fruit.name),                             label: {                                 HStack(alignment: .center) {                                     fruit.color.frame(width: 30, height: 30)                                     Text(fruit.name)                                 }                             })                             .swipeActions(edge: .leading, allowsFullSwipe: false) {                                 Button(action: { delete(fruit) },                                        label: { Image(systemName: "trash") }).tint(.red)                             }                     }                     .onMove(perform: { from, to in                         fruits.move(fromOffsets: from, toOffset: to)                     })                 }             }             .navigationBarTitle("Fruits")             .toolbar {                 ToolbarItem(placement: .primaryAction) {                     EditButton()                 }             }         }     }     private func delete(_ fruit: Fruit) {         guard let index = fruits.firstIndex(where: {$0.id == fruit.id}) else { return }         fruits.remove(at: index)     } } struct ListingView_Previews: PreviewProvider {     static var previews: some View {         ListingView()     } }
Replies
1
Boosts
0
Views
2.1k
Activity
Jul ’21