Instance Method


Determines whether to close the document, prompting the user as needed to choose a course of action.


- (void)canCloseDocumentWithDelegate:(id)delegate shouldCloseSelector:(SEL)shouldCloseSelector 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.


If the document is not dirty, this method immediately calls the shouldCloseSelector callback on the specified delegate with YES.

If the document is dirty, an alert is presented giving the user a chance to save, not save, or cancel. If the user chooses to save, this method saves the document. If the save completes successfully, this method calls the callback with YES. If the save is canceled or otherwise unsuccessful, this method calls the callback with NO. This method may be called by shouldCloseWindowController:delegate:shouldCloseSelector:contextInfo:. It is also called by the NSDocumentController method closeAllDocumentsWithDelegate:didCloseAllSelector:contextInfo:. You should call it before you call close if you are closing the document and want to give the user a chance to save any edits. Pass the contextInfo object with the callback.

The shouldCloseSelector callback method should have the following signature:

- (void)document:(NSDocument *)doc shouldClose:(BOOL)shouldClose  contextInfo:(void  *)contextInfo

See Also

Closing the Document

- close

Closes all of the document's windows and removes the document from its document controller.