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

# run()

Starts the main event loop.

```
func run()
```

## Discussion

The loop continues until a [`stop(_:)`](/documentation/AppKit/NSApplication/stop(_:)) or [`terminate(_:)`](/documentation/AppKit/NSApplication/terminate(_:)) message is received. Upon each iteration through the loop, the next available event from the window server is stored and then dispatched by sending it to `NSApp` using [`sendEvent(_:)`](/documentation/AppKit/NSApplication/sendEvent(_:)).

After creating the `NSApplication` object, the `main` function should load your app’s main nib file and then start the event loop by sending the `NSApplication` object a [`run()`](/documentation/AppKit/NSApplication/run()) message. If you create an Cocoa app project in Xcode, this `main` function is implemented for you.

## 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:)).

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

Starts a modal event loop for the specified window.

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

Tells the delegate that the app’s initialization is complete but it hasn’t received its first event.



---

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)