---
title: abortModal()
framework: appkit
role: symbol
role_heading: Instance Method
path: appkit/nsapplication/abortmodal()
---

# abortModal()

Aborts the event loop started by runModal(for:) or runModalSession(_:).

## Declaration

```swift
func abortModal()
```

## Discussion

Discussion When stopped with this method, runModal(for:) and runModalSession(_:) return NSModalResponseAbort. abortModal() must be used instead of stopModal() or 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(); otherwise, use abortModal(). For example, use 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

### Related Documentation

- [endModalSession(_:)](appkit/nsapplication/endmodalsession(_:).md)

### Running a Modal Window

- [runModal(for:)](appkit/nsapplication/runmodal(for:).md)
- [stopModal()](appkit/nsapplication/stopmodal().md)
- [stopModal(withCode:)](appkit/nsapplication/stopmodal(withcode:).md)
- [beginModalSession(for:)](appkit/nsapplication/beginmodalsession(for:).md)
- [runModalSession(_:)](appkit/nsapplication/runmodalsession(_:).md)
- [modalWindow](appkit/nsapplication/modalwindow.md)
- [NSApplication.ModalResponse](appkit/nsapplication/modalresponse.md)
- [NSApplication.ModalSession](appkit/nsapplication/modalsession.md)
