Instance Method


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


- (void)duplicateDocumentWithDelegate:(id)delegate didDuplicateSelector:(SEL)didDuplicateSelector contextInfo:(void *)contextInfo;



The delegate to which the selector message is sent.


The selector of the message sent to the delegate.


Object passed with the callback to provide any additional context information.


The new document that is created doesn’t yet have a value to return from fileURL. When duplicating is completed, regardless of success or failure, or whether the operation is rejected by the user, this method sends the message indicated by didDuplicateSelector to the delegate, with contextInfo as the last argument. The method selected by didDuplicateSelector must have the same signature as:

- (void)document:(NSDocument *)document didDuplicate:(BOOL)didDuplicate contextInfo:(void *)contextInfo;

The default implementation of this method first makes sure that any editor registered using the Cocoa Bindings NSEditorRegistration informal protocol has committed its changes, then checks to see if there are recent changes that might have been inadvertent and, if so, presents a panel giving the user the choice of canceling, duplicating, or duplicating then discarding recent changes. Unless the user cancels duplicating, or if no panel was presented, it then invokes duplicateAndReturnError:. If the user chose duplicating and discarding, it also discards recent changes after duplicating.

See Also

Duplicating the Document

- duplicateAndReturnError:

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

- duplicateDocument:

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