<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSApplicationDelegate/applicationShouldTerminateAfterLastWindowClosed(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSApplicationDelegate(im)applicationShouldTerminateAfterLastWindowClosed:"
  },
  "title" : "applicationShouldTerminateAfterLastWindowClosed(_:)"
}
-->

# applicationShouldTerminateAfterLastWindowClosed(_:)

Returns a Boolean value that indicates if the app terminates once the last window closes.

```
@MainActor optional func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool
```

## Parameters

`sender`

The application object whose last window was closed.

## Return Value

<doc://com.apple.documentation/documentation/Swift/false> if the application should not be terminated when its last window is closed; otherwise, <doc://com.apple.documentation/documentation/Swift/true> to terminate the application.

## Discussion

The application sends this message to your delegate when the application’s last window is closed. It sends this message regardless of whether there are still panels open. (A panel in this case is defined as being an instance of `NSPanel` or one of its subclasses.)

If your implementation returns <doc://com.apple.documentation/documentation/Swift/false>, control returns to the main event loop and the application is not terminated. If you return <doc://com.apple.documentation/documentation/Swift/true>, your delegate’s [`applicationShouldTerminate(_:)`](/documentation/AppKit/NSApplicationDelegate/applicationShouldTerminate(_:)) method is subsequently invoked to confirm that the application should be terminated.

## See Also

[`-  terminate:`](/documentation/AppKit/NSApplication/terminate(_:))

Terminates the receiver.



---

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)