The reference file document does not trigger any save action upon objectWillChange, assuming this is what trigger the write mechanism.
I've tested both using a simple String as the Snopshot type. As well as my production document model which is an ObservableObject.
Is it a bug? Or can Apple engineer provide a working example using ReferenceFileDocument?
version: XCode 12 beta 6
I've tested both using a simple String as the Snopshot type. As well as my production document model which is an ObservableObject.
Is it a bug? Or can Apple engineer provide a working example using ReferenceFileDocument?
version: XCode 12 beta 6
Recently, I've received feedback via the bug report and been suggested to register an undo.
Turnout, the update of ReferenceFileDocument can be triggered, just like UIDocument, by registering an undo action. The difference is that the DocumentGroup explicitly setup the UndoManager via the Environment.
For example,
Turnout, the update of ReferenceFileDocument can be triggered, just like UIDocument, by registering an undo action. The difference is that the DocumentGroup explicitly setup the UndoManager via the Environment.
For example,
Code Block @main struct RefDocApp: App { var body: some Scene { DocumentGroup(newDocument: { RefDocDocument() }) { file in ContentView(document: file.document) } } } struct ContentView: View { @Environment(\.undoManager) var undoManager @ObservedObject var document: RefDocDocument var body: some View { TextEditor(text: Binding(get: { document.text }, set: { document.text = $0 undoManager?.registerUndo(withTarget: document, handler: { print($0, "undo") }) })) } }