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

# terminate(_:)

Terminates the receiver.

```
func terminate(_ sender: Any?)
```

## Parameters

`sender`

Typically, this parameter contains the object that initiated the termination request.

## Discussion

This method is typically invoked when the user chooses Quit or Exit from the app’s menu.

When invoked, this method performs several steps to process the termination request. First, it asks the app’s document controller (if one exists) to save any unsaved changes in its documents. During this process, the document controller can cancel termination in response to input from the user. If the document controller doesn’t cancel the operation, this method then calls the delegate’s [`applicationShouldTerminate(_:)`](/documentation/AppKit/NSApplicationDelegate/applicationShouldTerminate(_:)) method. If [`applicationShouldTerminate(_:)`](/documentation/AppKit/NSApplicationDelegate/applicationShouldTerminate(_:)) returns [`NSApplication.TerminateReply.terminateCancel`](/documentation/AppKit/NSApplication/TerminateReply/terminateCancel), the termination process is aborted and control is handed back to the main event loop. If the method returns [`NSApplication.TerminateReply.terminateLater`](/documentation/AppKit/NSApplication/TerminateReply/terminateLater), the app runs its run loop in the [`NSModalPanelRunLoopMode`](/documentation/AppKit/NSModalPanelRunLoopMode) mode until the [`reply(toApplicationShouldTerminate:)`](/documentation/AppKit/NSApplication/reply(toApplicationShouldTerminate:)) method is called with the value <doc://com.apple.documentation/documentation/Swift/true> or <doc://com.apple.documentation/documentation/Swift/false>. If the [`applicationShouldTerminate(_:)`](/documentation/AppKit/NSApplicationDelegate/applicationShouldTerminate(_:)) method returns [`NSApplication.TerminateReply.terminateNow`](/documentation/AppKit/NSApplication/TerminateReply/terminateNow), this method posts a [`willTerminateNotification`](/documentation/AppKit/NSApplication/willTerminateNotification) notification to the default notification center.

Don’t bother to put final cleanup code in your app’s `main()` function—it will never be executed. If cleanup is necessary, perform that cleanup in the delegate’s [`applicationWillTerminate(_:)`](/documentation/AppKit/NSApplicationDelegate/applicationWillTerminate(_:)) method.

## See Also

[`stop(_:)`](/documentation/AppKit/NSApplication/stop(_:))

Stops the main event loop.

[`applicationShouldTerminate(_:)`](/documentation/AppKit/NSApplicationDelegate/applicationShouldTerminate(_:))

Returns a value that indicates if the app should terminate.

[`run()`](/documentation/AppKit/NSApplication/run())

Starts the main event loop.

[`applicationWillTerminate(_:)`](/documentation/AppKit/NSApplicationDelegate/applicationWillTerminate(_:))

Tells the delegate that the app is about to terminate.

[`willTerminateNotification`](/documentation/AppKit/NSApplication/willTerminateNotification)

Sends a notification to terminate the app.



---

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)