Post

Replies

Boosts

Views

Activity

UINavigationItemRenameDelegate does not work in IOS 16
I have an iPad app which is trying to support document renaming in the title bar. For IOS 17+ I set the renameDelegate to the document instance and it works fine. For IOS 16 I need to create an actual delegate, but no matter how I structure the code it fails with a permission error: Rename failed: “original_file_name” couldn’t be moved because you don’t have permission to access “Desktop”. It seems to always happen accessing the parent directory. I have tried using the file coordinator as well with the same result. It seems impossible to implement unless the callback contains a security permissioned url for the parent directory. Is there anyway to make this work in IOS 16 in the sandbox? Do I have to create my own rename functionality using a FilePicker? Seems like this should be built in like it is in MacOS, or even IOS17+ Here is the code: extension DocumentWindow : UINavigationItemRenameDelegate { func navigationItem(_ navigationItem: UINavigationItem, didEndRenamingWith title: String) { guard let doc = document else { return } let oldURL = doc.fileURL let newURL = oldURL.deletingLastPathComponent() .appendingPathComponent(title) .appendingPathExtension(oldURL.pathExtension) if newURL == oldURL { return } let access = oldURL.startAccessingSecurityScopedResource() defer { if access { oldURL.stopAccessingSecurityScopedResource() }} do { try FileManager.default.moveItem(at: oldURL, to: newURL) } catch { print("Rename failed: \(error.localizedDescription)") } // // // 1. Jump to a background queue to avoid the deadlock // DispatchQueue.global(qos: .userInitiated).async { // let coordinator = NSFileCoordinator(filePresenter: doc) // var error: NSError? // // // coordinator.coordinate(writingItemAt: oldURL, error: &error) { outOld in // do { // // 2. Perform the actual rename // try FileManager.default.moveItem(at: outOLD, to: newURL) // } catch { // print("Rename failed: \(error.localizedDescription)") // } // } // // if let error = error { // print("Coordination error: \(error.localizedDescription)") // } // } } // 2. Optional: Validation (e.g., prevent empty names) func navigationItem(_ navigationItem: UINavigationItem, shouldEndRenamingWith title: String) -> Bool { return !title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } }
0
0
14
15h
NSFileVersion doesn't work in IOS simulator?
I have the following code - you can see where I had to comment out the code on the simulator. Is this expected? The code works perfectly fine on a physical iPad device. Is it documented somewhere that NSFileVersion doesn't work with non-local versions in the simulator? func loadPreviewDirectly( from version: NSFileVersion, completion: @escaping (CIImage?) -> Void ) { let versionURL = version.url let access = versionURL.startAccessingSecurityScopedResource() defer { if access { versionURL.stopAccessingSecurityScopedResource() } } print("Loading version: \(version.persistentIdentifier) | Local: \(version.hasLocalContents)") // 1. SIMULATOR CATCH: If running in simulator and the file is missing, it will never download. #if targetEnvironment(simulator) if !version.hasLocalContents { print("⚠️ iOS Simulator cannot materialize remote NSFileVersions. Fallback triggered.") // You cannot test remote versions here. For testing on the simulator, // test with a version where version.hasLocalContents == true (created locally in this session). DispatchQueue.main.async { completion(nil) } return } #endif let coordinator = NSFileCoordinator() var coordinationError: NSError? // 2. Wrap everything in a sequential reading coordination coordinator.coordinate(readingItemAt: versionURL, options: [], error: &coordinationError) { readURL in let image = CIImage(contentsOf: readURL) DispatchQueue.main.async { completion(image) } } if let error = coordinationError { DispatchQueue.main.async { self.errorMessage = error.localizedDescription completion(nil) } } }
4
0
127
1w
segmented picker style causes runtime warning
On OSX, using a segmented picker style causes the following warning to be emitted (when a different selection is made) : "Publishing changes from within view updates is not allowed, this will cause undefined behavior." The warning is not emitted using the 'Preview Canvas' only when running the app. Changing the picker style to automatic also fixes it, but the segmented style is used extensively. Tested using XCode 26.4.1 on MacOS 26.3.1 --- view --- import SwiftUI internal import Combine enum Mode : String { case one, two, three } class MyObject : ObservableObject { @Published var mode : Mode = .one } struct ContentView: View { @StateObject var obj = MyObject() var body: some View { VStack { Picker("Mode",selection: $obj.mode) { Text("One").tag(Mode.one) Text("Two").tag(Mode.two) Text("Three").tag(Mode.three) } .pickerStyle(.segmented) } .padding() } } #Preview { ContentView() } --- app --- import SwiftUI @main struct SwiftUIBugApp: App { var body: some Scene { WindowGroup { ContentView() } } }
6
0
140
Apr ’26
SwiftUI crash on OSX 26 using NSColorPanel
Crashlog-0916-071225.log I have an app that crashes on OSX 26 only. I have a @StateObject which is an observer of the NSColorPanel. When I call let panel = NSColorPanel.shared in init(), SwiftUI will crash - apparently with an update while view is being updated. See crash log. I was able to work around it by adding let _ = NSColorPanel.shared in my AppDelegate before SwiftUI is initialized. The exact code worked fine in all previous OSX versions.
0
0
138
Sep ’25
NSDocumentController not adding "Open Recent" menu
I have a SwiftUI based app. For lots of reasons I was forced to use NSDocument instead of using DocumentGroup. I configure the main menu in my AppDelegate. It has the following code: let fileMenuItem = NSMenuItem() let fileMenu = NSMenu(title: "File") fileMenu.addItem(withTitle: "New", action: #selector(NSDocumentController.newDocument(_:)), keyEquivalent: "n") fileMenu.addItem(withTitle: "Open...", action: #selector(NSDocumentController.openDocument(_:)), keyEquivalent: "o") The New and Open work as expected. It is my understanding that the NSDocumentController should automatically add the "Open Recent" menu when it sees the Open action based on the NSDocumentController. It is not appearing. When I print the state of the recent documents using print("recent documents \(NSDocumentController.shared.recentDocumentURLs), maximum \(NSDocumentController.shared.maximumRecentDocumentCount)") I see the recent document urls and a count of 10. What can I do to make the menu appear? Thanks for the help.
5
0
309
Apr ’25
how to make certain undo registrations not mark the document as edited
Hi. I thought the purpose of UndoManager.setActionIsDiscardable() was for this purpose - but the document still shows as edited. These changes like changing the zoom/viewing area should not cause the document to be considered edited - but you'd still like to be able to undo them. The documentation here https://developer.apple.com/documentation/foundation/undomanager/1415261-undoactionisdiscardable?changes=_6 even describes using it for just this purpose. If this isn't the method, how can I do this? Thanks.
Topic: UI Frameworks SubTopic: AppKit
1
0
193
Mar ’25
SwiftUI revert to saved loads document multiple times
Using, the standard Apple example at https://developer.apple.com/documentation/swiftui/building-a-document-based-app-with-swiftui I only made a small change to print when reading a file, with the time. When you use 'revert to saved', it writes the current version (expected), then loads the saved version (expected), then a few seconds later (not moving the mouse, edits, etc.) it reloads the document again. Then if you click away from the window, it loads it yet again - four times! This loading of the document twice breaks apps where the loading may take longer (large documents), then the document is replaced while the user has already started editing the recently loaded document. This is a really bad bug. Any ideas? Here is the added logs: reading file! testfile.story at 2025-03-11 20:35:16 +0000 saving file! testfile.story at 2025-03-11 20:35:27 +0000 reading file! testfile.story at 2025-03-11 20:35:27 +0000 reading file! testfile.story at 2025-03-11 20:35:30 +0000 reading file! testfile.story at 2025-03-11 20:35:31 +0000 I see the same behavior with 'Revert To Last Opened'. It seems to work as expected when you browse all versions and pick a specific version.
1
0
267
Mar ’25
_dispatch_client_callout crash
I received the attached crash report. The problem is that the crash report does not contain the abort reason - it appears to be thrown in the GCD library with no additional information. Is it a possible deadlock? 2023-02-15_02-40-23.0077_+0100-94015bd052c4005658221a5e6279f28a75b9e92c.crash Any ideas?
5
0
2.4k
Mar ’25
high internal cpu usage
Hi, I am developing a new SwiftUI app. Running under OSX, I see very high cpu usage (I am generating lots of gpu based updates which shouldn't affect the cpu). I have used the profiler to ensure my swift property updates are minimal, yet the cpu usage is high coming from SwiftUI. It seems the high cpu usage is coming from NSAppearance, specifically, CUICopyMeasurements - for a single button??? But the swift updates don't show any buttons being updating
Topic: UI Frameworks SubTopic: SwiftUI
0
0
315
Feb ’25
NSImageInterpolationNone no longer works in Big Sur
As the developer of Seashore, using [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationNone]; no longer works as expected in Big Sur on a Retina display. The exact build works fine in Catalina. Small images seem to be first scaled using Medium or High interpolation to 2x, then scaled use 'None' to the desired size - causing blurriness. This the code to display and scale the image: [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationNone]; [image drawInRect:alignedRect fromRect:copy operation:NSCompositeSourceOver fraction:1.0 respectFlipped:TRUE hints:NULL]; Any ideas for a fix?
Topic: UI Frameworks SubTopic: AppKit Tags:
2
0
862
Jul ’21
UINavigationItemRenameDelegate does not work in IOS 16
I have an iPad app which is trying to support document renaming in the title bar. For IOS 17+ I set the renameDelegate to the document instance and it works fine. For IOS 16 I need to create an actual delegate, but no matter how I structure the code it fails with a permission error: Rename failed: “original_file_name” couldn’t be moved because you don’t have permission to access “Desktop”. It seems to always happen accessing the parent directory. I have tried using the file coordinator as well with the same result. It seems impossible to implement unless the callback contains a security permissioned url for the parent directory. Is there anyway to make this work in IOS 16 in the sandbox? Do I have to create my own rename functionality using a FilePicker? Seems like this should be built in like it is in MacOS, or even IOS17+ Here is the code: extension DocumentWindow : UINavigationItemRenameDelegate { func navigationItem(_ navigationItem: UINavigationItem, didEndRenamingWith title: String) { guard let doc = document else { return } let oldURL = doc.fileURL let newURL = oldURL.deletingLastPathComponent() .appendingPathComponent(title) .appendingPathExtension(oldURL.pathExtension) if newURL == oldURL { return } let access = oldURL.startAccessingSecurityScopedResource() defer { if access { oldURL.stopAccessingSecurityScopedResource() }} do { try FileManager.default.moveItem(at: oldURL, to: newURL) } catch { print("Rename failed: \(error.localizedDescription)") } // // // 1. Jump to a background queue to avoid the deadlock // DispatchQueue.global(qos: .userInitiated).async { // let coordinator = NSFileCoordinator(filePresenter: doc) // var error: NSError? // // // coordinator.coordinate(writingItemAt: oldURL, error: &error) { outOld in // do { // // 2. Perform the actual rename // try FileManager.default.moveItem(at: outOLD, to: newURL) // } catch { // print("Rename failed: \(error.localizedDescription)") // } // } // // if let error = error { // print("Coordination error: \(error.localizedDescription)") // } // } } // 2. Optional: Validation (e.g., prevent empty names) func navigationItem(_ navigationItem: UINavigationItem, shouldEndRenamingWith title: String) -> Bool { return !title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } }
Replies
0
Boosts
0
Views
14
Activity
15h
NSFileVersion doesn't work in IOS simulator?
I have the following code - you can see where I had to comment out the code on the simulator. Is this expected? The code works perfectly fine on a physical iPad device. Is it documented somewhere that NSFileVersion doesn't work with non-local versions in the simulator? func loadPreviewDirectly( from version: NSFileVersion, completion: @escaping (CIImage?) -> Void ) { let versionURL = version.url let access = versionURL.startAccessingSecurityScopedResource() defer { if access { versionURL.stopAccessingSecurityScopedResource() } } print("Loading version: \(version.persistentIdentifier) | Local: \(version.hasLocalContents)") // 1. SIMULATOR CATCH: If running in simulator and the file is missing, it will never download. #if targetEnvironment(simulator) if !version.hasLocalContents { print("⚠️ iOS Simulator cannot materialize remote NSFileVersions. Fallback triggered.") // You cannot test remote versions here. For testing on the simulator, // test with a version where version.hasLocalContents == true (created locally in this session). DispatchQueue.main.async { completion(nil) } return } #endif let coordinator = NSFileCoordinator() var coordinationError: NSError? // 2. Wrap everything in a sequential reading coordination coordinator.coordinate(readingItemAt: versionURL, options: [], error: &coordinationError) { readURL in let image = CIImage(contentsOf: readURL) DispatchQueue.main.async { completion(image) } } if let error = coordinationError { DispatchQueue.main.async { self.errorMessage = error.localizedDescription completion(nil) } } }
Replies
4
Boosts
0
Views
127
Activity
1w
segmented picker style causes runtime warning
On OSX, using a segmented picker style causes the following warning to be emitted (when a different selection is made) : "Publishing changes from within view updates is not allowed, this will cause undefined behavior." The warning is not emitted using the 'Preview Canvas' only when running the app. Changing the picker style to automatic also fixes it, but the segmented style is used extensively. Tested using XCode 26.4.1 on MacOS 26.3.1 --- view --- import SwiftUI internal import Combine enum Mode : String { case one, two, three } class MyObject : ObservableObject { @Published var mode : Mode = .one } struct ContentView: View { @StateObject var obj = MyObject() var body: some View { VStack { Picker("Mode",selection: $obj.mode) { Text("One").tag(Mode.one) Text("Two").tag(Mode.two) Text("Three").tag(Mode.three) } .pickerStyle(.segmented) } .padding() } } #Preview { ContentView() } --- app --- import SwiftUI @main struct SwiftUIBugApp: App { var body: some Scene { WindowGroup { ContentView() } } }
Replies
6
Boosts
0
Views
140
Activity
Apr ’26
SwiftUI crash on OSX 26 using NSColorPanel
Crashlog-0916-071225.log I have an app that crashes on OSX 26 only. I have a @StateObject which is an observer of the NSColorPanel. When I call let panel = NSColorPanel.shared in init(), SwiftUI will crash - apparently with an update while view is being updated. See crash log. I was able to work around it by adding let _ = NSColorPanel.shared in my AppDelegate before SwiftUI is initialized. The exact code worked fine in all previous OSX versions.
Replies
0
Boosts
0
Views
138
Activity
Sep ’25
NSDocumentController not adding "Open Recent" menu
I have a SwiftUI based app. For lots of reasons I was forced to use NSDocument instead of using DocumentGroup. I configure the main menu in my AppDelegate. It has the following code: let fileMenuItem = NSMenuItem() let fileMenu = NSMenu(title: "File") fileMenu.addItem(withTitle: "New", action: #selector(NSDocumentController.newDocument(_:)), keyEquivalent: "n") fileMenu.addItem(withTitle: "Open...", action: #selector(NSDocumentController.openDocument(_:)), keyEquivalent: "o") The New and Open work as expected. It is my understanding that the NSDocumentController should automatically add the "Open Recent" menu when it sees the Open action based on the NSDocumentController. It is not appearing. When I print the state of the recent documents using print("recent documents \(NSDocumentController.shared.recentDocumentURLs), maximum \(NSDocumentController.shared.maximumRecentDocumentCount)") I see the recent document urls and a count of 10. What can I do to make the menu appear? Thanks for the help.
Replies
5
Boosts
0
Views
309
Activity
Apr ’25
how to make certain undo registrations not mark the document as edited
Hi. I thought the purpose of UndoManager.setActionIsDiscardable() was for this purpose - but the document still shows as edited. These changes like changing the zoom/viewing area should not cause the document to be considered edited - but you'd still like to be able to undo them. The documentation here https://developer.apple.com/documentation/foundation/undomanager/1415261-undoactionisdiscardable?changes=_6 even describes using it for just this purpose. If this isn't the method, how can I do this? Thanks.
Topic: UI Frameworks SubTopic: AppKit
Replies
1
Boosts
0
Views
193
Activity
Mar ’25
How to disable auto-save in SwiftUI document based app?
My app typically works with very large image files. Having it auto-save on every change is very expensive as most formats cannot be saved incrementally. Is there a way to disable this and force the user to use the Save menu item on OSX, and possibly a Save button on iOS?
Replies
2
Boosts
0
Views
394
Activity
Mar ’25
Any way to change the UI for browse previous versions?
My UI is very heavyweight, so I'd like to show the previous versions using a lighter weight - almost like quick look - UI. This would also allow me to 'zoom to fit' so the entire document can be seen. I am using SwiftUI, but I wouldn't mind jumping into AppKit and/or UIKit to implement this.
Replies
3
Boosts
0
Views
276
Activity
Mar ’25
SwiftUI revert to saved loads document multiple times
Using, the standard Apple example at https://developer.apple.com/documentation/swiftui/building-a-document-based-app-with-swiftui I only made a small change to print when reading a file, with the time. When you use 'revert to saved', it writes the current version (expected), then loads the saved version (expected), then a few seconds later (not moving the mouse, edits, etc.) it reloads the document again. Then if you click away from the window, it loads it yet again - four times! This loading of the document twice breaks apps where the loading may take longer (large documents), then the document is replaced while the user has already started editing the recently loaded document. This is a really bad bug. Any ideas? Here is the added logs: reading file! testfile.story at 2025-03-11 20:35:16 +0000 saving file! testfile.story at 2025-03-11 20:35:27 +0000 reading file! testfile.story at 2025-03-11 20:35:27 +0000 reading file! testfile.story at 2025-03-11 20:35:30 +0000 reading file! testfile.story at 2025-03-11 20:35:31 +0000 I see the same behavior with 'Revert To Last Opened'. It seems to work as expected when you browse all versions and pick a specific version.
Replies
1
Boosts
0
Views
267
Activity
Mar ’25
_dispatch_client_callout crash
I received the attached crash report. The problem is that the crash report does not contain the abort reason - it appears to be thrown in the GCD library with no additional information. Is it a possible deadlock? 2023-02-15_02-40-23.0077_+0100-94015bd052c4005658221a5e6279f28a75b9e92c.crash Any ideas?
Replies
5
Boosts
0
Views
2.4k
Activity
Mar ’25
how do I enable Save As in File menu in SwiftUI?
The documentation here states that the saveItem command group placement contains the Save As as a default command, but it doesn't appear. I have my document type specifying multiple 'writableContentTypes' - I expected this would enable the save as. How do I do this?
Replies
4
Boosts
0
Views
377
Activity
Mar ’25
high internal cpu usage
Hi, I am developing a new SwiftUI app. Running under OSX, I see very high cpu usage (I am generating lots of gpu based updates which shouldn't affect the cpu). I have used the profiler to ensure my swift property updates are minimal, yet the cpu usage is high coming from SwiftUI. It seems the high cpu usage is coming from NSAppearance, specifically, CUICopyMeasurements - for a single button??? But the swift updates don't show any buttons being updating
Topic: UI Frameworks SubTopic: SwiftUI
Replies
0
Boosts
0
Views
315
Activity
Feb ’25
NSImageInterpolationNone no longer works in Big Sur
As the developer of Seashore, using [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationNone]; no longer works as expected in Big Sur on a Retina display. The exact build works fine in Catalina. Small images seem to be first scaled using Medium or High interpolation to 2x, then scaled use 'None' to the desired size - causing blurriness. This the code to display and scale the image: [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationNone]; [image drawInRect:alignedRect fromRect:copy operation:NSCompositeSourceOver fraction:1.0 respectFlipped:TRUE hints:NULL]; Any ideas for a fix?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
2
Boosts
0
Views
862
Activity
Jul ’21