Post

Replies

Boosts

Views

Activity

Reply to how to change appInfo in SwiftUI?
@Environment(\.openWindow) var openWindow Window("About", id: "about") {     MyAboutView() } .commands {     CommandGroup(replacing: .appInfo) {         Button(action: {             openWindow(id: "about")         }, label: {             Text("About MyAPP")         })     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’23
Reply to Custom File "New Document" to show template-picker in a document-based app
Answering my own question. I want to use Commands. See newItem. Here's an example: struct DocDemoApp: App {     @Environment(\.openWindow) var openWindow     @Environment(\.openDocument) private var openDocument     var body: some Scene {         DocumentGroup(newDocument: { DocDemoDocument() }) { config in             ContentView(document: config.document)         }         Window("Choose Template", id: "wizard") {             NewDocWizard()         }         .commands {             CommandGroup(replacing: .newItem) {                 Section {                     // Menu File >                     Button("New") { openWindow(id: "wizard") }.keyboardShortcut(KeyboardShortcut("N"))                     Button("Open") { open() }.keyboardShortcut(KeyboardShortcut("o"))                     Button("Open Recent...") { print("NYI") }                 }             }             CommandGroup(replacing: .singleWindowList) {                 // Menu Window > Choose Template, ... (list of single windows)                 // Hide and force user to use File > New for this window             }         }     }     private func open() {         let panel = NSOpenPanel()         panel.allowedContentTypes = [.exampleText]         panel.allowsMultipleSelection = true         panel.canChooseDirectories = false         panel.runModal()         if let url = panel.url {             Task {                 try! await openDocument(at: url)             }         }     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’23
Reply to (Xcode 14.0 beta 5) ThreadSanitizer: CHECK failed: tsan_platform_posix.cpp:83 "((beg)) <= ((end))"
On my Intel MBP is get a different error when the thread sanitizer is on. "malloc: nano zone abandoned due to inability to preallocate reserved vm space." StackOverflow suggests this is relatively harmless, but paired with the error I get on my Mac Mini (Apple Silicon) There's something afoul. [https://stackoverflow.com/questions/64126942/malloc-nano-zone-abandoned-due-to-inability-to-preallocate-reserved-vm-space]
Aug ’22
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
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 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 Unexpected intents
Solved. I had stupid dead code.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to NavigationSplitView detail view with safearea
Would safeAreaInset, applied to the button you want to be tappable, help? (I have not dealt a lot with safe areas so I am guessing.) How to inset the safe area with custom content: https://www.hackingwithswift.com/quick-start/swiftui/how-to-inset-the-safe-area-with-custom-content
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to TipKit: showing a popover tip on a SwiftUI toolbar button
Just don't use .automatic.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to Optionally use iCloud with SwiftData
My trouble was stale cache in the simulator or Mac. Restarting/rebooting a couple times helped.
Replies
Boosts
Views
Activity
Sep ’23
Reply to Enabling undo with multi-model schema
(Don't post while sleepy) Right in the docs... .modelContainer(for: [MyModel1.self, MyModel2.self], isUndoEnabled: true)
Replies
Boosts
Views
Activity
Aug ’23
Reply to how to change appInfo in SwiftUI?
@Environment(\.openWindow) var openWindow Window("About", id: "about") {     MyAboutView() } .commands {     CommandGroup(replacing: .appInfo) {         Button(action: {             openWindow(id: "about")         }, label: {             Text("About MyAPP")         })     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’23
Reply to Custom File "New Document" to show template-picker in a document-based app
Answering my own question. I want to use Commands. See newItem. Here's an example: struct DocDemoApp: App {     @Environment(\.openWindow) var openWindow     @Environment(\.openDocument) private var openDocument     var body: some Scene {         DocumentGroup(newDocument: { DocDemoDocument() }) { config in             ContentView(document: config.document)         }         Window("Choose Template", id: "wizard") {             NewDocWizard()         }         .commands {             CommandGroup(replacing: .newItem) {                 Section {                     // Menu File >                     Button("New") { openWindow(id: "wizard") }.keyboardShortcut(KeyboardShortcut("N"))                     Button("Open") { open() }.keyboardShortcut(KeyboardShortcut("o"))                     Button("Open Recent...") { print("NYI") }                 }             }             CommandGroup(replacing: .singleWindowList) {                 // Menu Window > Choose Template, ... (list of single windows)                 // Hide and force user to use File > New for this window             }         }     }     private func open() {         let panel = NSOpenPanel()         panel.allowedContentTypes = [.exampleText]         panel.allowsMultipleSelection = true         panel.canChooseDirectories = false         panel.runModal()         if let url = panel.url {             Task {                 try! await openDocument(at: url)             }         }     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’23
Reply to (Xcode 14.0 beta 5) ThreadSanitizer: CHECK failed: tsan_platform_posix.cpp:83 "((beg)) <= ((end))"
On my Intel MBP is get a different error when the thread sanitizer is on. "malloc: nano zone abandoned due to inability to preallocate reserved vm space." StackOverflow suggests this is relatively harmless, but paired with the error I get on my Mac Mini (Apple Silicon) There's something afoul. [https://stackoverflow.com/questions/64126942/malloc-nano-zone-abandoned-due-to-inability-to-preallocate-reserved-vm-space]
Replies
Boosts
Views
Activity
Aug ’22
Reply to (Xcode 14.0 beta 5) ThreadSanitizer: CHECK failed: tsan_platform_posix.cpp:83 "((beg)) <= ((end))"
I created a blank iOS app project in Xcode, enabled the thread sanitizer and it crashes exactly the same way on two simulators. I'm going to try a few more things to see how much might be me or Xcode.
Replies
Boosts
Views
Activity
Aug ’22
Reply to In SwiftUI, how do I stop a TextField from always beginning with initial caps?
I found that .autocapitalization(.none) doesn't work for me in iOS 15. I found .textInputAutocapitalization(.never) does work.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to An error occurred installing iOS 16 Developer Beta.
I have the iOS 16 profile installed but Software Update says I have 15.6 and I'm as up to date as I can be. I removed the profile and reinstalled it, yet it still refuses to install iOS 16.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Xcode 13 suddenly using old frameworks
Solved. Some slip of the mouse, perhaps, but the running target had changed to my Mac.
Replies
Boosts
Views
Activity
Sep ’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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Aug ’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:
Replies
Boosts
Views
Activity
Aug ’21