• 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: A problem of NSUserdefaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A problem of NSUserdefaults


  • Subject: Re: A problem of NSUserdefaults
  • From: Chris Parker <email@hidden>
  • Date: Thu, 13 Jul 2006 10:05:13 -0700

Hello,

On Jul 13, 2006, at 9:48 AM, Bus Mini wrote:

- (id)init
{
   [super init];
   NSMutableDictionary * defaultPrefs = [NSMutableDictionary
dictionary];
   [defaultPrefs setObject:@"Learning Cocoa"
forKey:@"FavBook"];
   [defaultPrefs setObject:@"San Francisco"
forKey:@"FavCity"];
   [defaultPrefs setObject:@"Red"
forKey:@"FavColor"];
   [defaultPrefs setObject:@"Mexican" forKey:@"FavFood"];

   prefs = [[NSUserDefaults standardUserDefaults]
retain];
   [prefs
registerDefaults:defaultPrefs];
   return self;
}

Your call to [prefs registerDefaults:defaultPrefs]; installs the key/ value pairs in the registration domain, which is volatile (i.e. not saved to disk). It's a "fallback" domain in the search list which you can use to place your application's default values.


Calling -synchronize does not write these values out.

If you were to do something like this later in your code:

     NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
     [defs setObject:@"New York" forKey:@"FavCity"];
     [defs synchronize];

Then the only key/value pair written to your application's preferences would be the FavCity/New York pair.

The conceptual docs on NSUserDefaults are here:

     http://developer.apple.com/documentation/Cocoa/Conceptual/UserDefaults/index.html

And you can get to the class reference from that page as well.

.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


References: 
 >A problem of NSUserdefaults (From: "Bus Mini" <email@hidden>)

  • Prev by Date: Re: A problem of NSUserdefaults
  • Next by Date: Re: Weird tabbing results
  • Previous by thread: Re: A problem of NSUserdefaults
  • Next by thread: Core Image morphing filter
  • Index(es):
    • Date
    • Thread