Post

Replies

Boosts

Views

Activity

Reply to List contents of NSUbiquitousKeyValueStore
Right after posting this I thought of a crude way to do it: dive into the app's sandbox on a simulator... /Users/«USER»/Library/Developer/CoreSimulator/Devices/«DEVICE»/data/Containers/Data/Application/«APP»/Library/SyncedPreferences/«BUNDLE».plist Good enough for debugging, but having a keys property would be better. I mean, if I need to clean up disused prefs I had really better never forget which keys were used when I shipped.
Apr ’21
Reply to Recommended way for testing CloudKit with two separate Apple Developer accounts?
I discussed this with developer support using up one of my 2 annual tickets. For people like me with individual developer accounts you cannot add other accounts to the team, at least not without ponying up for a second $99/year account. Instead the best option was to use a separate container for release. Just have to be sure to rebuild and test with the correct container before releasing the app :-)
May ’21
Reply to How to solve "Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates." error?
Answering my own question: Yes. when the issue occurs, go to the issues navigator, control-click any of the main-thread issues, and choose Create Breakpoint from the context menu. All main-thread issue will now break. (Xcode 9 used to have a "Pause on issues" checkbox but that is gone in Xcode 12.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to How to embed List in ScrollView using SwiftUI
Notes has a Recently Deleted folder view that shows a search field and some captions above the list. The whole vertical stack is scrollable. That makes me think they're using UIKit and not SwiftUI. Video Using ForEach with a Divider won't allow .swipeActions to work, as it must be inside a List.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to Why does .swipeAction set editMode?
I understand now. The Done button is useful for cancelling the swipe. swipe to reveal the hidden button(s) behind the row. decide you don't want to use those buttons. A) swipe the row back B) OR interact somewhere else C) OR tap Done to have the row return to normal. The EditMode isActive is true while the row is swiped aside, but the value is not .active.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21
Reply to How to add placeholder text to TextEditor in SwiftUI?
Here's my take on the ZStack method: ZStack(alignment: .topLeading) { TextEditor(text: $draftPreface)         .frame(height: 100)         .border(Color(uiColor: .opaqueSeparator), width: 0.5)     Text("preface").fontWeight(.light).foregroundColor(.black.opacity(0.25)).padding(8).hidden(!draftPreface.isEmpty) } I extended View with a conditional .hidden: extension View {     @ViewBuilder public func hidden(_ shouldHide: Bool) -> some View {         switch shouldHide {         case true: self.hidden()         case false: self         }     } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Jul ’21
Reply to How to implement custom type for onDrag and onInsert
Answering my own question. .onInsert only works with List. Use onDrop instead. The custom type should be declared final class MyType: NSObject, NSItemProviderWriting, NSItemProviderReading, Codable Here are some relevant code snippets that I hope help the next wanderer... import UniformTypeIdentifiers let MyTypeUTI: String = UTType.data.identifier // Very suspicious - will this allow ANY public.data to be dropped? Bad. final class MyType: NSObject, NSItemProviderWriting, NSItemProviderReading, Codable {     static var readableTypeIdentifiersForItemProvider: [String] = [MyTypeUTI]     static func object(withItemProviderData data: Data, typeIdentifier: String) throws -> Self {         let jsonDecoder = JSONDecoder()         let item = try! jsonDecoder.decode(Self.self, from: data)         return item     }     public enum Oops: Error {         case invalidTypeIdentifier     }     static var writableTypeIdentifiersForItemProvider: [String] = [MyTypeUTI]     func loadData(withTypeIdentifier typeIdentifier: String, forItemProviderCompletionHandler completionHandler: @escaping (Data?, Error?) -> Void) -> Progress? {         let progress = Progress(totalUnitCount: 100)         guard typeIdentifier == MyTypeUTI else { completionHandler(nil, Oops.invalidTypeIdentifier)             return progress         }         do {             let jsonEncoder = JSONEncoder()             let data = try jsonEncoder.encode(self)             completionHandler(data, nil)         }         catch { completionHandler(nil, error) }         return progress     } ...[The rest of MyType here]... Then to implement drag and drop in your View: ScrollView { VStack { ForEach(...) { item in ItemView(item)                     .onDrag({ NSItemProvider(object: item) })                     .onDrop(of: [MyTypeUTI],                             delegate: MyTypeDropDelegate(item: item, ...) Your DropDelegate might be like this (very rough code): struct MyTypeDropDelegate: DropDelegate {     let item: MyType     func performDrop(info: DropInfo) -> Bool {         let providers = info.itemProviders(for: [FigureBoxUTI])         guard let provider = providers.first else {             return false         }         provider.loadObject(ofClass: FigureBox.self) { item, error in             guard let box = box as? FigureBox else { ...handle error...                 return             }             ...handle drop of item...         }         return true     } } To be improved: I think that MyTypeUTI needs to be a custom string which extends public.data. UTIs are still a bit of a mystery to me since trying to use UTType was causing errors for me.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to printing with swiftui
I've seen Paul Hudson's sample on simple printing, (https://www.hackingwithswift.com/example-code/uikit/how-to-print-using-uiactivityviewcontroller). I'm still looking for how to present a system share sheet, which should allow me to "export" data to whatever form a share action wants, be it printing, tweeting, emailing, and so on. (Apple forums doesn't like me to post live URLs to that site: This domain "https://www.hackingwithswift.com/example-code/uikit/how-to-print-using-uiactivityviewcontroller" is not a permitted domain on this forums.) No sooner do I post this than I finally find an example that looks like it'll work (https://jeevatamil.medium.com/how-to-create-share-sheet-uiactivityviewcontroller-in-swiftui-cef64b26f073). I'll try to remember to post working code that connects this to printing.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to Attempt to map database failed
I put together a tiny demo using UIActivityViewController sharing a String. This also gets the "log noise" as Quinn so politely puts it. (My own choice term is not suitable for this forum.) I was surprised since I hadn't seen these message a day before, but maybe it correlates with beta 7.
Topic: Code Signing SubTopic: Entitlements Tags:
Aug ’21