Search code examples
cocoanswindownsalert

NSWindow display alert when attempt to close


How can I display an NSAlert when an NSWindow attempts to close? This will also have to be turned on and off.


Solution

  • NSWindow's delegate has a windowShouldClose: method that will allow you to customize this. There's also NSWindow's documentEdited methods that let you mark a document as having unsaved changes, which might interest you.