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

# stop(_:)

Stops the main event loop.

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

## Parameters

`sender`

The object that sent this message.

## Discussion

This method notifies the app that you want to exit the current run loop as soon as it finishes processing the current [`NSEvent`](/documentation/AppKit/NSEvent) object. This method doesn’t forcibly exit the current run loop. Instead it sets a flag that the app checks only after it finishes dispatching an actual event object. For example, you could call this method from an action method responding to a button click or from one of the many methods defined by the [`NSResponder`](/documentation/AppKit/NSResponder) class. However, calling this method from a timer or run-loop observer routine wouldn’t stop the run loop because they don’t result in the posting of an [`NSEvent`](/documentation/AppKit/NSEvent) object.

If you call this method from an event handler running in your main run loop, the app object exits out of the [`run()`](/documentation/AppKit/NSApplication/run()) method, thereby returning control to the `main()` function. If you call this method from within a modal event loop, it will exit the modal loop instead of the main event loop.

## See Also

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

Runs a given modal session, as defined in a previous invocation of [`beginModalSession(for:)`](/documentation/AppKit/NSApplication/beginModalSession(for:)).

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

Terminates the receiver.

[`runModal(for:)`](/documentation/AppKit/NSApplication/runModal(for:))

Starts a modal event loop for the specified window.



---

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)