Reputation: 1664
My document-based app immediately terminates the document upon cmd+w and it is not saved. How can I react to this and either prompt for saving the document or automatically save it?
Upvotes: 1
Views: 54
Reputation: 14824
Use the NSDocument
method updateChangeCount(_:)
to mark your document as edited, and Cocoa will take care of the rest!
Furthermore, if you use NSUndoManager
for all changes, it updates the change count for you!
Most of the time, you should look for these kinds of "hooks" into existing Cocoa functionality, so that your app behaves exactly the same way as other OS X apps, and so that you inherit new features when new OS versions are released.
Upvotes: 1