Instance Method

autosave(completionHandler:)

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

Declaration

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

Parameters

completionHandler

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

success

true if the autosaving operation succeeds, otherwise false.

The block is invoked on the calling queue.

Discussion

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(UIDocumentChangeKind)

Update the change counter by indicating the kind of change.

var undoManager: UndoManager!

The undo manager for the document.

func changeCountToken(for: UIDocumentSaveOperation)

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

func updateChangeCount(withToken: Any, for: UIDocumentSaveOperation)

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