Re: What writes out a pref file?
Re: What writes out a pref file?
- Subject: Re: What writes out a pref file?
- From: Bill Bumgarner <email@hidden>
- Date: Thu, 14 Apr 2005 15:19:19 -0700
On Apr 14, 2005, at 3:10 PM, Dan Yocom wrote:
I think you need to add the following line:
// save preferences to the user's home directory/Library/Preferences.
[prefs writeToFile:[@"~/Library/Preferences/com.appName.plist"
stringByExpandingTildeInPath] atomically: TRUE];
No -- you really, really, rally don't want to do that. It totally
bypasses the user defaults API that is provided exactly for managing
user defaults.
Proper answer is below.
On 4/14/05, Mark Dawson <email@hidden> wrote:
I added the following code to my +initialize method for my
appController:
NSMutableDictionary *dict;
NSUserDefaults *defaults;
defaults=[NSUserDefaults standardUserDefaults];
dict=[NSMutableDictionary dictionary];
[dict setObject:[defaults
objectForKey:@"AppleMeasurementUnits"]
forKey:@"MyMeasurements"]; // starts out the same as
AppleMeasurementUnits
[defaults registerDefaults:dict];
However, I don't see the above key in my "com.appName.plist" file
in my
~/Library/Preferences/ folder (the last mod date is yesterday). What
do I need to do to write out new values? From what I could tell,
launching and quitting should write it out, right? Or do I need to
call something like synchronize?
This is correct behaivor.
You don't see the value in your app's preferences file because you
haven't changed the value. Registration defaults are the baseline
set of values to be used for the defaults. That is, they are the
values that the program will use if there wasn't a custom value found
in the user defaults.
Imagine this; at some later date, you decide the out-of-the-box
default should be "Radians" instead of whatever is returned by
"AppleMeasurementUnits". By using a registration default, every
user of your app that never changed away from the default value will
automatically start using 'radians' instead. At the same time, any
user that customized the default value will have their custom default
value preserved.
If you were to call [[NSUserDefaults standardUserDefaults]
setStringValue: @"Radians" forKey: @"MyMeasurements"], then that
custom value will be written when the app is quit. You can call
[[NSUserDefaults standardUserDefaults] synchronize] to force the
values to be written Right Now -- very useful when sharing defaults
between multiple applications.
b.bum
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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