quitting xcode cocoa swift app quitting xcode cocoa swift app swift swift

quitting xcode cocoa swift app


You should be able to just call terminate on the global NSApp object.

@IBAction func ExitNow(sender: AnyObject) {    NSApplication.sharedApplication().terminate(self)}

Edit With Swift 3 the code is now:

@IBAction func ExitNow(sender: AnyObject) {    NSApplication.shared().terminate(self)}

Edit 2 With Swift 4 & 5 the code is now:

@IBAction func ExitNow(sender: AnyObject) {    NSApplication.shared.terminate(self)}


Or we could simply exit from the app like this:

@IBAction func ExitNow(sender: AnyObject) {        exit(0)}

As a side note you can exit because of an error:

fatalError("reason for exiting")

Unconditionally prints a message and stops execution. iOS 8.1 and later.


In Xcode 9.0 you might use NSApp.terminate(nil).