-1

I've created a Mac OS X application, and during the development it was fine because I opened it with Xcode.

But now, I try to execute the executable and it's working only the first time, because after close the window, the app persists in memory. And I have to kill it with the activity monitor.

So what should I do to kill the app when I touch the red top left button on the window?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user1573607
  • 522
  • 9
  • 23
  • 1
    possible duplicate of [Quit app when NSWindow closes](http://stackoverflow.com/questions/3941960/quit-app-when-nswindow-closes) – Monolo Jan 04 '13 at 16:58

2 Answers2

3
- (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)application
{
return YES;
}
1

Override the windowWillClose method in your delegate to make it terminate the app.

- (void)windowWillClose:(NSNotification *)aNotification {
    [NSApp terminate:self];
}
DNax
  • 1,413
  • 1
  • 19
  • 29
  • Won't that close the program if any window is closed, regardless if it is the last one? –  Jan 04 '13 at 17:10
  • Yes, the applicationShouldTerminateAfterLastWindowClosed approach is more suitable but the windowWillClose came to my mind because I figured the app in question as a one-window app. – DNax Jan 04 '13 at 17:22