Re: NSUersDefaults and setting for a specific domain
Re: NSUersDefaults and setting for a specific domain
- Subject: Re: NSUersDefaults and setting for a specific domain
- From: Chris Parker <email@hidden>
- Date: Tue, 26 Sep 2006 13:16:48 -0700
On Sep 26, 2006, at 1:09 PM, David Alter wrote:
I'm working on a plugin. If I use NSUersDefaults to get and set the
prefs, it ends up making changes in the host applications prefs
file. I wanted to make sure the plugin prefs end up in it's own
prefs file. I was wondering if there was an easy way to insure that
the prefs are set for the correct domain.
I can get the data for the correct domain by doing the following
id value = [[[NSUserDefaults standardUserDefaults]
persistentDomainForName: @"com.mycompany.myplugin"]
objectForKey: key];
And I could set it by doing...
NSMutableDictionary * defaults = [NSMutableDictionary
dictionaryWithDictionary:[[NSUserDefaults standardUserDefaults]
persistentDomainForName: @"com.mycompany.myplugin"]];
[defaults setObject: value forKey:key];
[[NSUserDefaults standardUserDefaults] setPersistentDomain:defaults
forName:@"ccom.mycompany.myplugin"];
But I'm guessing there is a cleaner way to do this.
There is, but it means dropping "down" to CFPreferences. Key/value
pairs set via CFPreferences are available through NSUserDefaults and
vice-versa.
Getting your value:
id value = CFPreferencesCopyAppValue(yourKey,
CFSTR("com.mycompany.myplugin"));
And setting it:
CFPreferencesSetAppValue(yourKey, yourValue,
CFSTR("com.mycompany.myplugin"));
CFPreferencesAppSynchronize(CFSTR("com.mycompany.myplugin"));
.chris
--
Chris Parker
Cocoa Frameworks
Apple Computer, Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden