Instance Method


Called by UIKit to initiate automatic saving of documents with unsaved changes.


func autosave(completionHandler: ((Bool) -> Void)? = nil)



A block with code to execute after automatic saving concludes. The block returns no value and has one parameter:


true if the autosaving operation succeeds, otherwise false.

The block is invoked on the calling queue.


UIDocument periodically invokes this method to initiate a save operation if there are unsaved changes. You should not call this method directly. Subclasses can override it if they want to do special things with autosaving. The default implementation of this method invokes the hasUnsavedChanges method and, if that returns true, it invokes the save(to:for:completionHandler:) method.

This method should only be invoked for period-based saves. You may invoke it with the success parameter of the completion-handler parameter set to false and return; this makes it safe to not actually save when autosaveWithCompletionHandler: is invoked. However, if you call save(to:for:completionHandler:), saving of document data must occur.

See Also

Tracking Changes and Autosaving

var hasUnsavedChanges: Bool

Returns whether the document has any unsaved changes.

func updateChangeCount(UIDocument.ChangeKind)

Update the change counter by indicating the kind of change.

var undoManager: UndoManager!

The undo manager for the document.

func changeCountToken(for: UIDocument.SaveOperation) -> Any

Overridden to return a change token for a specific save operation.

func updateChangeCount(withToken: Any, for: UIDocument.SaveOperation)

Overridden to update the change count with reference to a change-count token passed in by UIKit.