You do not even need to write an action method for this purpose. The "file owner" of the main nib is an instance of NSApplication that represents the running application, and it has a terminate: method that terminates the application.
So, just connect your button to the terminate: method terminate: "File Owner". You can see that the "Exit" entry in the menu bar provided by the interface builder is connected to the same method of the same target.
If you really insist, do
-(IBAction)exitApp:(NSButton*)sender { [[NSApplication sharedApplication] terminate:nil]; }
Finally, note that the application is not made to exit , but the application is made in quit . So, on your button, do not put the Exit shortcut ... it's Windows-rev. Use the verb Exit instead. The terminate verb in the method selector is NextStep-ism, remaining in Cocoa terminology, but you should not use it in the visible parts of your application.
Another thing is that you can implement the delegate method
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication { return YES; }
so that the application closes automatically when the last window is closed, and then you can end the quit button. See the documentation .
source share