Instance Method

unblockUserInteraction()

Unblocks the main thread during asynchronous saving.

Declaration

func unblockUserInteraction()

Discussion

If save(to:ofType:for:completionHandler:) is writing on a non-main thread because canAsynchronouslyWrite(to:ofType:for:) has returned true, but it is still blocking the main thread, this method unblocks the main thread. Otherwise, it does nothing. For example, the default implementation of fileWrapper(ofType:) invokes this when it has created the FileWrapper object to return. Assuming that the NSFileWrapper is not mutated by subsequent user actions, it is effectively a "snapshot" of the document’s contents, and once it is created it is safe to resume handling user events on the main thread, even though some of those user events might change the document’s contents before the NSFileWrapper object has been safely written. You can invoke this method to make asynchronous saving actually asynchronous if you’ve overridden writeSafely(to:ofType:for:), write(to:ofType:for:originalContentsURL:), or write(to:ofType:) in such a way that the invocation of this method done by the write(to:ofType:) default implementation won’t happen during writing.

See Also

Reading From and Writing to URLs

func read(from: URL, ofType: String)

Sets the contents of this document by reading from a file or file package, of a specified type, located by a URL.

func write(to: URL, ofType: String)

Writes the contents of the document to a file or file package located by a URL, formatted to a specified type.

func writeSafely(to: URL, ofType: String, for: NSDocument.SaveOperationType)

Writes the contents of the document to a file or file package located by a URL.

func write(to: URL, ofType: String, for: NSDocument.SaveOperationType, originalContentsURL: URL?)

Writes the contents of the document to a file or file package located by a URL.

func fileAttributesToWrite(to: URL, ofType: String, for: NSDocument.SaveOperationType, originalContentsURL: URL?) -> [String : Any]

As a file is being saved, returns the attributes that should be written to a file or file package located by a URL, formatted to a specified type, for a particular kind of save operation.

func save(to: URL, ofType: String, for: NSDocument.SaveOperationType, delegate: Any?, didSave: Selector?, contextInfo: UnsafeMutableRawPointer?)

Saves the contents of the document to a file or file package located by a URL, formatted to a specified type, for a particular kind of save operation.

func canAsynchronouslyWrite(to: URL, ofType: String, for: NSDocument.SaveOperationType) -> Bool

Returns whether the receiver can concurrently write to a file or file package located by a URL, formatted for a specific type, for a specific kind of save operation.

func changeCountToken(for: NSDocument.SaveOperationType) -> Any

Returns an object that encapsulates the current record of document changes at the beginning of a save operation.

func save(to: URL, ofType: String, for: NSDocument.SaveOperationType, completionHandler: (Error?) -> Void)

Saves the contents of the document to a file or file package located by a URL, formatted to a specified type, for a particular kind of save operation, and invokes the passed-in completion handler.

func updateChangeCount(withToken: Any, for: NSDocument.SaveOperationType)

Records the fact that saving has succeeded and updates related aspects of the change count mechanism.