Instance Method

initWithContentsOfURL:ofType:error:

Initializes a document located by a URL of a specified type.

Declaration

- (instancetype)initWithContentsOfURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError * _Nullable *)outError;

Parameters

absoluteURL

The URL from which the contents of the document are obtained.

typeName

The string that identifies the document type.

outError

On return, if initialization is unsuccessful, a pointer to an error object that encapsulates the reason the document could not be created.

Return Value

The initialized NSDocument object, or, if the document could not be created, nil.

Discussion

You can override this method to customize the reopening of autosaved documents.

This method is invoked by the NSDocumentController method makeDocumentWithContentsOfURL:ofType:error:. The default implementation of this method calls the init and readFromURL:ofType:error: methods and sets values for the fileURL, fileType, and fileModificationDate properties.

For backward binary compatibility with OS X v10.3 and earlier, the default implementation of this method instead invokes initWithContentsOfFile:ofType: if it is overridden and the URL uses the file: scheme. It still updates the fileModificationDate property in this situation.

See Also

Initializing

- init

Initializes and returns an empty NSDocument object.

- initForURL:withContentsOfURL:ofType:error:

Initializes a document located by a URL of a specified type, but by reading the contents for the document from a different URL.

- initWithType:error:

Initializes a document of a specified type.