ReferenceFileDocument DOES NOT saving!

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
Answered by FrankZR in 634269022
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,

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")
})
}))
}
}

Same problem here using Xcode12 beta6
Same on Xcode12 beta 6 and iPadOS 14 beta 8.
Accepted Answer
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,

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")
})
}))
}
}

ReferenceFileDocument DOES NOT saving!
 
 
Q