Contents

makeDocument(for:withContentsOf:ofType:)

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

func makeDocument(for urlOrNil: URL?, withContentsOf contentsURL: URL, ofType typeName: String) throws -> NSDocument

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.

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 documentClass(forType:) to find out the class of document to instantiate, allocates a document object, and initializes it by sending it an init(for:withContentsOf:ofType:) message.

See Also

Creating and Opening Documents