tags:

views:

72

answers:

2

I have a little Cocoa Application that needs to save its settings. Is it the best practice to save every time to user made a change or is it better to save once only when the application is ended?

Is there any event raised when the application should end or the window should close?

+6  A: 

The NSUserDefaults class can (should) be used to manage users settings.

The class will save the user settings 'from time to time' and also before the app closes.

You can also force saving by calling the synchronize method.

Robert Christie
Sounds perfect. Thanks a lot.
Holli
+1  A: 

I would say save every time the user makes a change. Writing to the defaults store is pretty fast (especially on the desktop compared to the iPhone). Also, if your application crashes or is force quitted, the settings won't be lost (since the NSApplication delegate methods such as applicationWillTerminate: won't be called).