How to make a macOS App quit when you press the red close button?

Hi!

I am making an app with Mac OS X Snow Leopard and XCode version 3. I can't figure out how to make the app quit when you press the red "close" button in the top left corner. Could you please tell me how to do this?

Replies

Xcode 3???!!??!!


Still, the answer has been around since OS X 10.0, so you're in luck.


In your application delegate .m file, implement this delegate method:


     - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
     {
          return YES;
     }


and the app should terminate automatically when that main window is closed.