I currently have a plist which contains some configuration values; at start of
day I use the following call to make certain "factory settings" available to
the application through NSUserDefaults:
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary
dictionaryWithContentsOfFile:configPath]];
This works fine with single-object keys. i.e. I can include a key of type
Number in the plist file, and it will be made available in the same way as
other user defaults.
However some of my user defaults are organised within a dictionary (e.g. there
is a dictionary for each separate camera connected to the system, tracking
user-controllable defaults such as chosen framerate). I would like a way to
contribute factory settings from my plist for some of those key values. However
if I include a dictionary in my plist, and separately call
[[NSUserDefaults standardUserDefaults] setObject:aDictionary
forDefault:@"my_camera_key"];
then this dictionary object fully overrides the entire dictionary object that I
supplied for my_camera_key in the plist. I had thought there was an outside
chance that it would effectively merge the two dictionaries together, looking
for a specific key first in the dictionary object in the user-specified
defaults and then falling back to the dictionary object I supplied through
registerDefaults. This does not appear to be the case though.
Not sure if this makes sense - perhaps an example will help.
plist supplied to registerDefaults contains:
"my_camera_key" <dictionary>
"my_camera_key"."key1" = 4
"my_camera_key"."key2" = 5
dictionary passed to setObject:forDefault:@"my_camera_key" contains:
"key1"=7
"key3"=1
I had vaguely hoped that if I then called
[[NSUserDefaults standardUserDefaults] objectForKey:@"my_camera_key"]
then I might get back a dictionary containing three objects:
"key1"=7
"key2"=5
"key3"=1
Can anyone suggest how I might achieve what I am trying to do here? (Or suggest
a better mechanism of doing what I want to do, i.e. maintain some sort of
hierarchy to my defaults, but also be able to supply factory settings for
objects below the top level of the hierarchy?
Thanks for any suggestions
Jonny
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]