How to disable auto-save in SwiftUI document based app?

My app typically works with very large image files. Having it auto-save on every change is very expensive as most formats cannot be saved incrementally.

Is there a way to disable this and force the user to use the Save menu item on OSX, and possibly a Save button on iOS?

Answered by DTS Engineer in 829104022

SwiftUI document-based API, or DocumentGroup + FileDocument / ReferenceFileDocument, doesn't provide a direct way for disabling auto-save, nor does it privide any good way for customizing the reading / writing process. I’d hence suggest that you file a feedback report with your use case to request the features – If you do so, please share your report ID here for folks to track.

When you use FileDocument, auto-save is triggered after the system detects a change on the document; for ReferenceFileDocument, auto-save is tied to a registration on the undo manager. If really needed, you might be able to control the save timing by deferring your change on the document or undo stack.

To handle large files with a customized reading / writing process, you might consider using UIDocument / NSDocument instead. The Synchronizing documents in the iCloud environment covers this topic.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Accepted Answer

SwiftUI document-based API, or DocumentGroup + FileDocument / ReferenceFileDocument, doesn't provide a direct way for disabling auto-save, nor does it privide any good way for customizing the reading / writing process. I’d hence suggest that you file a feedback report with your use case to request the features – If you do so, please share your report ID here for folks to track.

When you use FileDocument, auto-save is triggered after the system detects a change on the document; for ReferenceFileDocument, auto-save is tied to a registration on the undo manager. If really needed, you might be able to control the save timing by deferring your change on the document or undo stack.

To handle large files with a customized reading / writing process, you might consider using UIDocument / NSDocument instead. The Synchronizing documents in the iCloud environment covers this topic.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I needed to move to an NSDocument based solution to make all of this work.

How to disable auto-save in SwiftUI document based app?
 
 
Q