SwiftUI: Why use ReferenceFileDocument vs FileDocument?

I'm building a document-based app in SwiftUI.

I see you can have a document that is a value type using FileDocument or a document that is a reference type using ReferenceFileDocument.

There is no discussion in the documentation or in the WWDC session as to when you should use one instead of the other. From the WWDC session, it seems that FileDocument is the preferred approach.

What are the use cases / conditions when it would make more sense to use a ReferenceFileDocument?

What are the drawbacks of FileDocument that ReferenceFileDocument addresses?

Thank you for any insights on this.
Can we please get an answer from an Apple engineer on this?

I am also struggling to understand how to use ReferenceFileDocument correctly. An example of proper usage would be greatly appreciated!
After some trial and error I think I have created a working example of using ReferenceFileDocument. You can find the code here. I hope this helps someone else!
Hi,

has anybody figured out in the meantime the why's and when's (James original questions)?

I am currently trying to develop a macOS app with SwiftUI's new app lifecycle and a document package as persistence and am really struggling to find out what the best approach here is...

Thanks!
ReferenceFileDocument is for auto-saving documents in the background. It uses UndoManager to know when to save a document.

See this thread..

And here is a working example.

The "Building a Great Mac App with SwiftUI" sample, part 2 has an ObservableObject data model that is manually loaded and saved but in an extension it implements ReferenceFileDocument for a CSV export feature. Fyi to make it work move .fileExporter from the Button to Section.

SwiftUI: Why use ReferenceFileDocument vs FileDocument?
 
 
Q