• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSUersDefaults and setting for a specific domain
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: NSUersDefaults and setting for a specific domain
      • From: Mailing list subscriptions <email@hidden>
    • Re: NSUersDefaults and setting for a specific domain
      • From: "Stephen Deken" <email@hidden>
References: 
 >NSUersDefaults and setting for a specific domain (From: David Alter <email@hidden>)

  • Prev by Date: NSUersDefaults and setting for a specific domain
  • Next by Date: Re: NSUersDefaults and setting for a specific domain
  • Previous by thread: NSUersDefaults and setting for a specific domain
  • Next by thread: Re: NSUersDefaults and setting for a specific domain
  • Index(es):
    • Date
    • Thread