• 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: Advice: Plugin preference strategy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advice: Plugin preference strategy


  • Subject: Re: Advice: Plugin preference strategy
  • From: Allen Brunson <email@hidden>
  • Date: Fri, 3 Feb 2006 06:04:50 -0600


On Feb 2, 2006, at 6:01 PM, John Pannell wrote:

Thanks Dirk-

This was certainly my gut instinct, but then the high-level interface cannot be used: NSUserDefaults will only operate on my app's prefs plist - not any other domain's.

not true! i can see how you could get that impression, though. it took me quite awhile to figure out how to use NSUserDefaults for non- default domains. i'll just cut-and-paste the notes i made for myself when i first figured it out:


* Saving prefs between apps *

NSUserDefaults will let you load and store data between apps, but the docs
are not at all helpful on how you go about it. First, you have to settle on
a "domain name" for your shared prefs, which will be known by all apps that
wish to access them. For example, org.domain.MySharedDefaults or something
similar. As far as I can tell, you have to read and write the entire prefs
file in one go, in the form of an NSDictionary of key-object pairs. There
are apparently no methods to read and write single objects at a time, as
there are for the app's private prefs file. To read the whole prefs file:


NSUserDefaults* ndef = [NSUserDefaults standardUserDefaults];
NSDictionary* dict = [ndef persistentDomainForName:@"org.some.Prefs"];


You can query 'dict' for key-value objects stored in the file, the same as
you would for the app's private prefs file.


When it's time to write a new set of data, you can copy 'dict' to an
NSMutableDictionary, add new stuff or make changes as necessary, then put
it all back, like this:


NSMutableDictionary* data = [NSMutableDictionary dictionaryWithCapacity:5];

  [data addEntriesFromDictionary:dict];
  // make changes, deletions, and additions here
  [ndef setPersistentDomain:data forName:@"org.some.Prefs"];

You'll end up with an xml file called org.some.Prefs.plist in the current
user's preferences directory.


_______________________________________________
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


References: 
 >Advice: Plugin preference strategy (From: John Pannell <email@hidden>)
 >Re: Advice: Plugin preference strategy (From: Dirk Stegemann <email@hidden>)
 >Re: Advice: Plugin preference strategy (From: John Pannell <email@hidden>)

  • Prev by Date: Re: ceil woes
  • Next by Date: Property name clashes with a method implemented by NSManagesObject or NSObject
  • Previous by thread: Re: Advice: Plugin preference strategy
  • Next by thread: Re: Core Data: updating a key dependent on a to-many relationship?
  • Index(es):
    • Date
    • Thread