<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocumentController/closeAllDocuments(withDelegate:didCloseAllSelector:contextInfo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocumentController(im)closeAllDocumentsWithDelegate:didCloseAllSelector:contextInfo:"
  },
  "title" : "closeAllDocuments(withDelegate:didCloseAllSelector:contextInfo:)"
}
-->

# closeAllDocuments(withDelegate:didCloseAllSelector:contextInfo:)

Iterates through all the open documents and tries to close them one by one using the specified delegate.

```
func closeAllDocuments(withDelegate delegate: Any?, didCloseAllSelector: Selector?, contextInfo: UnsafeMutableRawPointer?)
```

## Parameters

`delegate`

The object responsible for closing the document.

`didCloseAllSelector`

The selector to call after all documents have been closed.

`contextInfo`

A pointer to user-supplied data.

## Discussion

Each `NSDocument` object is sent [`canClose(withDelegate:shouldClose:contextInfo:)`](/documentation/AppKit/NSDocument/canClose(withDelegate:shouldClose:contextInfo:)), which, if the document is dirty, gives it a chance to refuse to close or to save itself first. This method may ask whether to save or to perform a save.

The `didCloseAllSelector` callback method is called with <doc://com.apple.documentation/documentation/Swift/true> if all documents are closed, and <doc://com.apple.documentation/documentation/Swift/false> otherwise. Pass the `contextInfo` object with the callback. The `didCloseAllSelector` callback method should have the following signature:

```objc
- (void)documentController:(NSDocumentController *)docController  didCloseAll:(BOOL)didCloseAll contextInfo:(void *)contextInfo
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)