Instance Method

read(from:ofType:)

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

Declaration

func read(from url: URL, ofType typeName: String) throws

Parameters

absoluteURL

The location from which the document contents are read.

typeName

The string that identifies the document type.

outError

On return, if the document contents could not be read, a pointer to an error object that encapsulates the reason they could not be read.

Return Value

true if the document contents could be read; otherwise, false.

Discussion

The default implementation of this method just creates an NSFileWrapper and invokes [self readFromFileWrapper:theFileWrapper ofType:typeName error:outError].

For backward binary compatibility with OS X v10.3 and earlier, the default implementation of this method instead invokes [self readFromFile:[absoluteURL path] ofType:typeName] if readFromFile:ofType: is overridden and the URL uses the file: scheme.

See Also

Reading From and Writing to URLs

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.

func unblockUserInteraction()

Unblocks the main thread during asynchronous saving.