If you want to block a window from closing, the NSWindow's delegate is where it's at. Be it either the AppDelegate (which is the default for most Xcode templates) or an NSWindowController if that's how you presented your window. The method you want to implement from NSWindowDelegate is -windowShouldClose:
or -windowWillClose:
. If you want to prevent the closing of the window, simply return NO
from -windowShouldClose:
.
If you want to stop the app from quitting, you should look into NSApplicationDelegate and override -applicationShouldTerminate:
and return NSTerminateCancel
to prevent the app from terminating.
In short, the "should" methods allow you to prevent the action from occurring, the "will" methods are just saying that it will happen and you can deal with it.