PDA

View Full Version : Saving states using NSUserDefaults




xmax
Feb 25, 2009, 02:31 AM
I am binding check box value with shared user defaults controller in Interface Builder. I am registering defaults as well.
but user defaults not working. it doesn't saves the status of check box.
There is no plist file created at path /Library/Preferences for my application identifier.


Thanks

xmax



Bakerman
Feb 25, 2009, 04:24 AM
The plist file isn't created at /Library/Preferences, it is created at ~/Library/Preferences.

Make sure that you use the controller key 'values' and then another name like e.g. 'CheckBoxValue' for the model key path.

xmax
Feb 25, 2009, 04:33 AM
Sorry, But i have checked for ~/Library/Preferences.
There is no any plist file created over there.
can you tell me the steps from beginning for saving states of check box.
I have given model key path for check box but i am not getting.

kainjow
Feb 25, 2009, 01:53 PM
Your bindings might be setup wrong. Can you post a picture of IB with the bindings inspector selected for your checkbox?

xmax
Feb 26, 2009, 05:14 AM
I am sending you my test application in attachment ?

you can find what is the problem ?


Thanks.

xmax
Feb 26, 2009, 06:23 AM
I got what was the problem ?
Actually i was quiting application from debugger. so it was not saving the state of check box. once i quit from Application Menu , it saved the state.
So, I can understand that it will save the states on quiting the application, not on registering defaults.

That concludes , to save the state we have to quit the application. or we can use the method synchronize or setValue:forKey to save the state when application is Running.

am i correct ? what is correct method to save?


Thanks.

kainjow
Feb 26, 2009, 06:35 AM
Yes, synchronize is what you'd use to save it without waiting until restart. Most of the time you don't need this, just don't kill the app and let it terminate normally.