<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocument/shouldCloseWindowController(_:delegate:shouldClose:contextInfo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocument(im)shouldCloseWindowController:delegate:shouldCloseSelector:contextInfo:"
  },
  "title" : "shouldCloseWindowController(_:delegate:shouldClose:contextInfo:)"
}
-->

# shouldCloseWindowController(_:delegate:shouldClose:contextInfo:)

Determines whether the system should close the document and its associated window.

```
func shouldCloseWindowController(_ windowController: NSWindowController, delegate: Any?, shouldClose shouldCloseSelector: Selector?, contextInfo: UnsafeMutableRawPointer?)
```

## Parameters

`windowController`

The window controller that is closed.

`delegate`

The delegate to which the selector message is sent.

`shouldCloseSelector`

The selector of the message sent to the delegate.

`contextInfo`

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

## Discussion

If the window controller is the document’s last one, or is marked as causing the document to close, this method calls the method in the `shouldCloseSelector` parameter with the result of [`canClose(withDelegate:shouldClose:contextInfo:)`](/documentation/AppKit/NSDocument/canClose(withDelegate:shouldClose:contextInfo:)). In all other cases, this method calls `shouldCloseSelector` with <doc://com.apple.documentation/documentation/Swift/true>. This method is called automatically by [`NSWindow`](/documentation/AppKit/NSWindow) for any window that has a window controller and a document associated with it. `NSWindow` calls this method prior to sending its `delegate` the [`windowShouldClose(_:)`](/documentation/AppKit/NSWindowDelegate/windowShouldClose(_:)) message. Pass the `contextInfo` object with the callback.

The `shouldCloseSelector` callback method should have the following signature:

```objc
- (void)document:(NSDocument *)document shouldClose:(BOOL)shouldClose  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)