OK, I admit NSUserDefaults
, being a Mac-specific thing (and me being a Mac programmer for the last couple of years), is one of the things I haven't delved into that much... so here are some issues/questions I've come across :
I understand that NSUserDefaults
is basically an NSMutableDictionary
written as a .plist
.
My questions :
Given that I'm running OS X 10.7 (Lion) and having enabled Sandbox, where is my app's .plist file? (I've search in both
~/Library/Preferences/com.example.myapp.plist
and~/Library/Containers/com.example.myapp/Data/Library/Preferences/com.example.myapp.plist
but none of these seems validI understand that this
.plist
file is created the first time the app launches, correct?registerDefaults:
is to be used at application launch (e.g. inawakeFromNib
) and provide a Dictionary of default values that are immediately stored in the.plist
file, and changed only if a different value is set at some point, correct?When we're setting a specific Key-Value pair, is that pair automatically and immediately saved to the
.plist
file? And if so, why/when should we usesynchronize
? (Is using it every single time some value is set an overkill, or should it be reserved for special cases?)
Sidenote : I hope nobody complains about my use of the osx
tag. However, I'm really tired of seeing Cocoa Touch / iOS related answers to my (mostly) OSX-related questions. So, here you are... :-)
EDIT : For some really helpful insight on the subject, please have a look at the accepted answer as well as the comments below it.