Re: NSUserDefaults for another Application
Re: NSUserDefaults for another Application
- Subject: Re: NSUserDefaults for another Application
- From: Keith Duncan <email@hidden>
- Date: Thu, 26 Jul 2007 11:03:38 +0100
You can use CFPreferences to do this. The snippets below show
setting and getting a value from a TextField:
appID = CFSTR("uk.co.watershed.communicate.client");
....
/* initialise the Full name field */
value =
CFPreferencesCopyAppValue( CFSTR("WSPublishUserFullName"), appID);
if (value && CFGetTypeID(value) == CFStringGetTypeID()) {
[fullName setStringValue:(NSString *)value];
....
and saving values...
....
CFPreferencesSetValue( CFSTR("WSPublishUserFullName"),
[fullName stringValue],
kCFPreferencesAnyApplication,
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
I could do that but it would be a lot of code to load and save every
value in the preference file.
I have tried using NSUserDefaults to get the persistentDomainForName
using the bundle id which works fine for loading the prefs, but when
it comes to saving the prefs with setPersistentDomain:forName: it
doesn't.
Say I have a key-object pair present in the dictionary after loading
it and I remove that object at runtime, when saving the preference
dictionary using setPersistentDomain:forName: the key-object pair
remains in the preference file. I assume that my own alloc'd
NSUserDefaults objects also register for the application termination
notification and synchronize then without being explicitly told to?
- Keith
- Keith
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden