I’ve recently updated to MacOSX Mavericks and have run into some issues with our Mac App’s User Defaults,
it seemed that for some reason, the defaults stored in
~/Library/Preferences/<com.example.myapp>.plist are somehow being "ignored"
if you changed settings in there by hand or even delete the whole plist file, the app seems to still remember those settings, and magically the file will
appear again !
So how did this happen ? there doesn’t seem to be enough information about it, so I dug in a little bit and here’s my findings !
Apps have their own “Containers” in mavericks, storing their different settings in there.
Using NSUserDefaults, your app will look into the Container first, then in our good ‘ol
OSX will also the move settings in the container to
if it’s not found.
Using your terminal, cd into
the contents, you’ll find lots of symlinks to apple’s app settings and in between, your app’s
.plist file,which won’t be a symlink, that’s where you should be editing your prefs.
TipI usually don’t recommend editing plist files manually, I’d rather use a tool called
simply fire up a terminal, and try this:
defaults read com.example.myapp
Sweet, huh ?!, that’s just scratching the surface ! using this tool you can read, edit or create any defaults you want, think “NSUserDefaults” for the terminal !
Why?, well consider this, if you weren’t modifying the defaults by hand, and using this tool instead, you would never had any issues with Mavericks.
If you have apps that play around with the defaults on the filesystem, use the
tool instead, it’ll never break.
let me know your findings/thoughts in the comments !
TipIf you need to quickly reset your app’s state, run this in the terminal:
defaults delete com.myapp.* && rm -rf ~/Library/Preferences/com.myapp.*