Post

Replies

Boosts

Views

Activity

Reply to Mixing ReferenceFileDocument and @Observable
The data model is only a class so it can adopt @Observable - otherwise it could be a Struct. Even if it were a Struct, I don't know how to connect it to an @Observable class instance without losing the use of the Undo manager. I don't know if @State shares the ability of @Observable to only update views that need to be redrawn following a data model change.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’25
Reply to Mixing ReferenceFileDocument and @Observable
When I register Undos, I name them so that I can make the undo available via a menu selection that shows specifically what will be undone or redone. Hoping that a shake gesture will work seems much less desirable than giving the user explicit control over undo / redo - and in any event, I've read that the Undo manager doesn't actually work with SwiftData.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’25
Reply to Can a ReferenceFileDocument be @Observable?
Update: Observation seems to work correctly when I use ObservedObject and @Published . BUT, when I switch back to @Observable and @Environment (as it was before making the app document based), the application hangs mysteriously. I'd sure love to see a working example of a document based app that uses an @Observable data model! Particularly if it used a non-trivial data model, and isolates the document behaviour elegantly. For now, I'm assuming that it's just not possible, although I'd expect it to be a common use case. BTW, one reason that I use @Observable is that I have hundreds of views, and I'm assuming that observation will be more efficient if I don't explicitly pass a binding to the model in every one of those views.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’25