Instance Method

duplicate()

Creates a new document whose contents are the same as the receiver and returns an error object if unsuccessful.

Declaration

func duplicate() throws -> NSDocument

Parameters

outError

On return, if the document could not be duplicated, a pointer to an error object that encapsulates the reason why it could not be duplicated.

Return Value

The new document if duplication is successful; otherwise nil.

Discussion

The new document returned doesn’t yet have a value to return from fileURL.

The default implementation of this method first uses writeSafely(to:ofType:for:) to write the document’s current contents to a file located in the same directory that is used for the autosaved contents of untitled documents and with the same sort of name, then invokes [[NSDocumentController sharedDocumentController] duplicateDocumentWithContentsOfURL:newContentsURL copying:NO displayName:aDisplayName error:outError].

You can override this method to customize what is done during document duplication, but if your override does not invoke [NSDocumentController duplicateDocumentWithContentsOfURL:copying:displayName:error:] you must take care to do things that that method does, especially invoking [NSDocumentController addDocument:] and [NSFileCoordinator addFilePresenter:].

See Also

Duplicating Documents

func duplicate(Any?)

Creates a copy of the receiving document in response to the user choosing Duplicate from the File menu.

func duplicate(withDelegate: Any?, didDuplicate: Selector?, contextInfo: UnsafeMutableRawPointer?)

Create a new document whose contents are the same as the receiver’s and notify the delegate.