FileDocument / ReferenceFileDocument deferred save issue

I'm using FileDocument (and also tested ReferenceFileDocument) in a SwiftUI app. As usual, saving changes is deferred & handled automatically when you modify the document (or register an undo action for ReferenceFileDocument).

I've noticed if you edit the data / document, then quickly exit your app (back to the file selection), then re-open the same file, it provides the old file content (from before the edit was made). If you exit and re-open again (or just wait 10-15 seconds from the original edit), it all works fine and the new changes are present.

This occurs on both iOS 14 and iOS 15.

Anyone else seen this behavior?

I see exactly this behavior on iOS 14. This behavior would astonish my users. Needs to be fixed ASAP. I wish I saw a way to trigger a save on a change of scene phase.

I still see problems regarding saving Documents even in iOS 16 with FileDocument. i understand that FileDocument is when you use structs and it detects changes and should save. But it doesn’t seem too reliable.

i just wish i could trigger/force save. any solutions?

FileDocument / ReferenceFileDocument deferred save issue
 
 
Q