Instance Method

makeDocumentForURL:withContentsOfURL:ofType:error:

Instantiates a document located by a URL, of a specified type, but by reading the contents for the document from another URL, and returns it if successful.

Declaration

- (__kindof NSDocument *)makeDocumentForURL:(NSURL *)urlOrNil withContentsOfURL:(NSURL *)contentsURL ofType:(NSString *)typeName error:(NSError * _Nullable *)outError;

Parameters

urlOrNil

The location of the new document object.

contentsURL

The URL of the file that provides the contents for the new document.

typeName

The type of the document.

outError

On return, an error if the document could not be created, otherwise nil.

Return Value

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

Discussion

The URL is specified by absoluteDocumentURL, the type by typeName, and the other URL providing the contents by absoluteDocumentContentsURL. If not successful, the method returns nil after setting outError to point to an NSError object that encapsulates the reason why the document could not be instantiated. The default implementation of this method calls documentClassForType: to find out the class of document to instantiate, allocates a document object, and initializes it by sending it an initForURL:withContentsOfURL:ofType:error: message.

See Also

Creating and Opening Documents

- documentForURL:

Returns, for a given URL, the open document whose file or file package is located by the URL, or nil if there is no such open document.

- duplicateDocumentWithContentsOfURL:copying:displayName:error:

Creates a new document by reading the contents for the document from another URL, presents its user interface, and returns the document if successful.

- openDocumentWithContentsOfURL:display:completionHandler:

Opens a document located by a URL, optionally presents its user interface, and calls the passed-in completion handler.

- openUntitledDocumentAndDisplay:error:

Creates a new untitled document, presents its user interface if displayDocument is YES, and returns the document if successful.

- makeDocumentWithContentsOfURL:ofType:error:

Instantiates a document located by a URL, of a specified type, and returns it if successful.

- makeUntitledDocumentOfType:error:

Instantiates a new untitled document of the specified type and returns it if successful.

- reopenDocumentForURL:withContentsOfURL:display:completionHandler:

Reopens a document, optionally located by a URL, by reading the contents for the document from another URL, optionally presents its user interface, and calls the passed-in completion handler.