Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A problem of NSUserdefaults



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

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



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.