Instance Property


Returns the document type that should be used for an autosave operation.


var autosavingFileType: String? { get }


This properties contains a string that identifies the document type for autosave files. The default implementation just returns the value provided by the fileType property. You can override this property and return nil to completely disable autosaving of individual documents (because the NSDocumentController object does not call the autosave(withDelegate:didAutosave:contextInfo:) method of a document that has no autosaving file type). You can also override it if your app defines a document type that is specifically designed for autosaving, for example, one that efficiently represents document content changes instead of complete document contents.

Overriding this property can result in incorrect behavior during reopening of autosaved documents. The NSDocument method init(for:withContentsOf:ofType:), which is invoked during reopening of autosaved documents after a crash, takes two URLs, but only the type name of the autosaved contents file. The default implementation updates the fileType property with that type name, but that may not be the right thing to do if this property contains something other than fileType during document autosaving. If you override autosavingFileType, you probably need to override init(for:withContentsOf:ofType:) too, and make the override update fileType with the type of the actual document file, after invoking super. See TextEdit’s Document class for an example of how to do this.

See Also


func checkAutosavingSafety()

Returns a Boolean value indicating whether it is probably safe to autosave document changes.

func scheduleAutosaving()

Schedules periodic autosaving for the purpose of crash protection.

var hasUnautosavedChanges: Bool

A Boolean value indicating whether the document has changes that have not been autosaved.

func autosave(withImplicitCancellability: Bool, completionHandler: (Error?) -> Void)

Autosaves the document’s contents at an appropriate location if it needs autosaving.

class var autosavesInPlace: Bool

Returns whether the receiver supports autosaving in place.

class var autosavesDrafts: Bool

Returns whether the receiving subclass of NSDocument supports autosaving of drafts.

class var preservesVersions: Bool

Returns whether the receiving subclass of NSDocument supports Versions.

func browseVersions(Any?)

Opens the Versions browser in the document’s main window.

var autosavingIsImplicitlyCancellable: Bool

A Boolean value indicating whether autosaving is happening now but could be safely cancelled.

var autosavedContentsFileURL: URL?

The location of the most recently autosaved document contents.