Contents

close(completionHandler:)

Asynchronously closes the document after saving any changes.

Declaration

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

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 didn’t succeed (success is false), you can respond in an appropriate manner.

You typically wouldn’t override this method. The default implementation calls the autosave(completionHandler:) method.

See Also

Writing document data