runModal(for:)
Starts a modal event loop for the specified window.
Declaration
func runModal(for window: NSWindow) -> NSApplication.ModalResponseParameters
- window:
The window to be displayed modally. If it is not already visible, the window is centered on the screen using the value in its Center() method and made visible and key. If it is already visible, it is simply made key.
Return Value
An integer indicating the reason that this method returned. See NSApplication.ModalResponse possible return values.
Discussion
This method runs a modal event loop for the specified window synchronously. It displays the specified window, makes it key, starts the run loop, and processes events for that window. (You do not need to show the window yourself.) While the app is in that loop, it does not respond to any other events (including mouse, keyboard, or window-close events) unless they are associated with the window. It also does not perform any tasks (such as firing timers) that are not associated with the modal run loop. In other words, this method consumes only enough CPU time to process events and dispatch them to the action methods associated with the modal window.
You can exit the modal loop by calling the stopModal(), stopModal(withCode:), or abortModal() methods from your modal window code. If you use the stopModal(withCode:) method to stop the modal event loop, this method returns the argument passed to stopModal(withCode:). If you use stopModal() instead, this method returns the constant stop. If you use abortModal(), this method returns the constant abort.