I have built a SwiftUI FileDocument app like this.
I'm a bit confused how to use the $document Binding.
I know with ObservableObject I can do:
How can I react to changes on $document in my Non-GUI code?
Use case: I'm building an app, where for some changes in the document, there's a command sent over the network. This command should also be sent, if I use e.g. undo. That's why I don't want so send these updates from within my View but as a reaction to a change in $document.
Code Block struct MyApp: App { var body: some Scene { DocumentGroup(newDocument: MyFileDocument()) { file in DocumentView(document: file.$document) } } }
I'm a bit confused how to use the $document Binding.
I know with ObservableObject I can do:
Code Block document.objectWillChange .sink { _ in print("Document changed") }
How can I react to changes on $document in my Non-GUI code?
Use case: I'm building an app, where for some changes in the document, there's a command sent over the network. This command should also be sent, if I use e.g. undo. That's why I don't want so send these updates from within my View but as a reaction to a change in $document.