Re: Ghost value in NSUserDefaults
Re: Ghost value in NSUserDefaults
- Subject: Re: Ghost value in NSUserDefaults
- From: Stephan Burlot <email@hidden>
- Date: Sun, 9 Jan 2005 21:00:32 +0100
The problems is that in my app, if the key "Country" has no content in
the context of my User Domain, NSUserDefault will give me the value of
the "Country" key in the GlobalPreferences.
What I dont understand (and I suppose there's a bug somewhere), is that
such an obvious key as "Country" is stored in the GlobalPrefs.
I've changed my key to "CountryCode" and it's OK now.
BTW, I will try use this key to detect the country of the user, along
with keyboard used and locale.
Thanks
Stephan
Le 9 janv. 05, à 19:30, Kevin Ballard a écrit :
+[NSUserDefaults standardUserDefaults] gives you an NSUserDefaults
object with several domains pre-existing. The first domain, IIRC, are
keys passed in through the command-line arguments (if you call an app
via the command-line you can override defaults there). The second
domain is user internationalization settings and the like, such as the
language and country. The third domain is the preferences from the
application's prefs file. The fourth domain is the registration
domain. When you ask it for a value, it goes down the domains in
order. So when you ask it for COUNTRY_KEY it finds the result in the
2nd domain and never even looks at the 4th (where you registered the
empty values).
This is just off the top of my head, so I could have some details
wrong, but I believe that's how it works.
On Jan 9, 2005, at 8:47 AM, Stephan Burlot wrote:
I start my application and do:
#define COUNTRY_KEY @"Country"
NSUserDefaults *userDefaults = [NSUserDefaults
standardUserDefaults];
NSDictionary *defaultValues = [NSDictionary
dictionaryWithObjectsAndKeys:
@"", SERVICE_KEY,
@"", COUNTRY_KEY,
@"", LANGUAGE_KEY,
@"", USERNAME_KEY,
@"", PASSWORD_KEY,
nil, ALERT_KEY,
@"No", MODE_KEY,
@"", DEFAULT_PAPERID_KEY,
@"", SERVICE_ID_FOR_PAPER_KEY,
nil];
[userDefaults registerDefaults:defaultValues];
NSLog(@"country: %@", [[NSUserDefaults standardUserDefaults]
objectForKey:COUNTRY_KEY]);
and I get:
country: CH
Where does this value comes from?
--
Kevin Ballard
email@hidden
http://www.tildesoft.com
http://kevin.sb.org
_______________________________________________
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