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

# abortModal()

Aborts the event loop started by [`runModal(for:)`](/documentation/AppKit/NSApplication/runModal(for:)) or [`runModalSession(_:)`](/documentation/AppKit/NSApplication/runModalSession(_:)).

```
func abortModal()
```

## Discussion

When stopped with this method, [`runModal(for:)`](/documentation/AppKit/NSApplication/runModal(for:)) and [`runModalSession(_:)`](/documentation/AppKit/NSApplication/runModalSession(_:)) return `NSModalResponseAbort`.

[`abortModal()`](/documentation/AppKit/NSApplication/abortModal()) must be used instead of [`stopModal()`](/documentation/AppKit/NSApplication/stopModal()) or [`stopModal(withCode:)`](/documentation/AppKit/NSApplication/stopModal(withCode:)) when you need to stop a modal event loop from anywhere other than a callout from that event loop. In other words, if you want to stop the loop in response to a user’s actions within the modal window, use [`stopModal()`](/documentation/AppKit/NSApplication/stopModal()); otherwise, use [`abortModal()`](/documentation/AppKit/NSApplication/abortModal()). For example, use [`abortModal()`](/documentation/AppKit/NSApplication/abortModal()) when running in a different thread from AppKit’s main thread or when responding to an `NSTimer` that you have added to the `NSModalPanelRunLoopMode` mode of the default `NSRunLoop`.

## See Also

[`func endModalSession(NSApplication.ModalSession)`](/documentation/AppKit/NSApplication/endModalSession(_:))

Finishes a modal session.



---

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)