Post

Replies

Boosts

Views

Activity

Reply to Error when clicking on TextField : CLIENT ERROR: TUINSRemoteViewController does not override -viewServiceDidTerminateWithError: and thus cannot react to catastrophic errors beyond logging them
Sonoma 14.5, Xcode 16.0 (16A242d) Pure SwiftUI application, MacOS (document-based), a single TextView with a binding instead of the template solution with added UndoManager functionality (which seems unnecessary). The error does not happen every time: – if I type in an existing document, it's fine; if I switch to Xcode and back to my app, the error appears. – if I create a new document and select the existing string, it's fine. If I create a second new document and select the string in that, I get the error. – if I switch between two dirty unsaved documents, I get the error. and so on. I'm reasonably confident there are patterns to this, but I don't have the time or patience to try all of them.
3d
Reply to How to preview a custom View that takes bindings as inputs in its initializer?
This was driving me mad as well, because half the examples (including in this state answer 'how do I preview a @Binding' with 'here's a working example using @State' which misses the point by a mile. I've found different workarounds elsewhere that also didn't work for me. What does work, however, is to replace @Binding with @Bindable. And suddenly, the standard #Preview macro works out of the box. #Preview { BindingViewExample_2(value: true) }
Jul ’24
Reply to Swift file reading permission error on macOS sandbox
I had this problem with trying to create an NSImage from a URL retrieved from an openDialog (well, a SwiftUI .fileImporter) even after setting the UserSelectedFile Sandbox permission. (If it's 'none', it'll crash, so it's hard to get that one wrong). The fileImporter retrieves a valid URL, but cannot access the file anyway. (This used to work). The answer is to make the resource explicitly accessible: _ = selectedFileURL.startAccessingSecurityScopedResource() guard let image = NSImage(contentsOf: selectedFileURL) else { return } selectedFileURL.stopAccessingSecurityScopedResource()
Jun ’24