I'm using NSUserDefaults (on Mac OS X 10.9) to store some string value (if there is none already):
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
_kUpdatesSharedLocationPath = [standardUserDefaults stringForKey:UpdatesSharedLocationPath];
if (_kUpdatesSharedLocationPath == nil) {
_kUpdatesSharedLocationPath = [@"/Volumes/My.store"];
[standardUserDefaults setObject:@"/Volumes/My.store" forKey:VestigaUpdatesSharedLocationPath];
}
[standardUserDefaults synchronize];
This is working fine and write a value in my file system, under /Users/piotr/Library/Preferences/com.company.MyApp.plist
Next, I want to modify this value from a console (my application is not running during this process):
$ defaults write com.company.MyApp UpdatesSharedLocationPath -string SomeOtherValue
This change is correctly reflected in my file system, in /Users/piotr/Library/Preferences/com.company.MyApp.plist
But when I launch my application again, the value is still the same as before defaults write
in console. I inspect it by reading a value [standardUserDefaults stringForKey:UpdatesSharedLocationPath]
and by [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]
. What's more, value in my file system(/Users/piotr/Library/Preferences/com.company.MyApp.plist
) switches back to the one before the change in console.
I tried editing value without a domain, but the same results:
$ defaults write UpdatesSharedLocationPath -string SomeOtherValue
What's more, I tried to delete this key in my defaults:
$ defaults delete com.company.MyApp UpdatesSharedLocationPath
but it was re-created, with the value before deletion.
It seems like my app and [NSUserDefaults standardUserDefaults]
is completely ignoring all changes I do using console defaults
program. Is that expected behaviour? Should I specify a different domain in defaults
?
How can I change (from outside of my app) values managed by NSUserDefaults
?