Instance Method


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


- (__kindof NSDocument *)duplicateAndReturnError:(NSError * _Nullable *)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.


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

The default implementation of this method first uses writeSafelyToURL:ofType:forSaveOperation:error: 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 the Document

- duplicateDocument:

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

- duplicateDocumentWithDelegate:didDuplicateSelector:contextInfo:

Creates a new document whose contents are the same as the current document.