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

# run()

Starts the main event loop.

## Declaration

```swift
func run()
```

## Discussion

Discussion The loop continues until a stop(_:) or 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(_:). 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() message. If you create an Cocoa app project in Xcode, this main function is implemented for you.

## See Also

### Related Documentation

- [runModalSession(_:)](appkit/nsapplication/runmodalsession(_:).md)
- [runModal(for:)](appkit/nsapplication/runmodal(for:).md)
- [applicationDidFinishLaunching(_:)](appkit/nsapplicationdelegate/applicationdidfinishlaunching(_:).md)

### Managing the event loop

- [nextEvent(matching:until:inMode:dequeue:)](appkit/nsapplication/nextevent(matching:until:inmode:dequeue:).md)
- [discardEvents(matching:before:)](appkit/nsapplication/discardevents(matching:before:).md)
- [currentEvent](appkit/nsapplication/currentevent.md)
- [isRunning](appkit/nsapplication/isrunning.md)
- [finishLaunching()](appkit/nsapplication/finishlaunching().md)
- [stop(_:)](appkit/nsapplication/stop(_:).md)
- [sendEvent(_:)](appkit/nsapplication/sendevent(_:).md)
- [postEvent(_:atStart:)](appkit/nsapplication/postevent(_:atstart:).md)
