Instance Method

close(completionHandler:)

Asynchronously closes the document after saving any changes.

Declaration

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

Parameters

completionHandler

A block with code to execute after the save-and-close operation concludes. The block returns no value and has one parameter:

success

true if any save operation succeeds, otherwise false.

The block is invoked on the main queue.

Discussion

You call this method to begin the sequence of method calls that saves a document safely and asynchronously. The file-system location of the document derives from the fileURL property. After the save operation concludes, the code in completionHandler is executed. In this code, you can close the document—for example, by removing the document’s view from the screen. Additionally, if the save operation did not succeed (success is false), you can respond in an appropriate manner.

You typically would not override this method. The default implementation calls the autosave(completionHandler:) method.

See Also

Related Symbols

func writeContents(Any, andAttributes: [AnyHashable : Any]? = nil, safelyTo: URL, for: UIDocumentSaveOperation)

Ensures that document data is written safely to a specified location in the application sandbox.

func contents(forType: String)

Override this method to return the document data to be saved.

func writeContents(Any, to: URL, for: UIDocumentSaveOperation, originalContentsURL: URL?)

Writes the document data to disk at the sandbox location indicated by a file URL.

func save(to: URL, for: UIDocumentSaveOperation, completionHandler: ((Bool) -> Void)? = nil)

Saves document data to the specified location in the application sandbox.