Re: Sharing preferences between applications
Re: Sharing preferences between applications
- Subject: Re: Sharing preferences between applications
- From: Esteban Uribe <email@hidden>
- Date: Mon, 12 May 2003 22:22:12 -0700
Hey,
On Monday, May 12, 2003, at 09:50 PM, Arthur VIGAN wrote:
>
Hi,
>
>
how can I share a preference file between two (or more) applications?
>
Should I use persistent domain names? if yes, how does that work?
Persistent domain names are basically the names of the preference files
in ~/Library/Preferences.
They are persistent because they are saved to disk.
You can create additional persistent domains which will have an
equivalent .plist file saved is
~/Library/Preferences with the domain name you choose.
You can load these domains using the standardUserDefaults, and calling
persistentDomainForName:
You get back an NSDictionary with the information. You can the set the
persistentDomain
once you change the contents of the NSDictionary by calling -
setPersistentDomain:forName:
Here's a quick example on reading from a persistent domain (aka .plist
in ~/Library/Preferences)
- (void)importOldPreferences:(BOOL)shouldImport
{
id domain;
if(shouldImport == YES) {
if([[prefs persistentDomainNames]
containsObject:kBetaDomainName]) {
int result = 0;
NSString *domainLocation = [[NSString
stringWithFormat:@"~/Library/Preferences/%@.plist", kBetaDomainName]
stringByExpandingTildeInPath];
NSBeep();
result = NSRunAlertPanel(@"Preference Import", [NSString
stringWithFormat:@"Found Old Prefences file at:\n%@.\n\nImporting this
file is recommended.\n\nChoose wait if you plan to backup this
file.\n", domainLocation], @"Import", @"Wait", nil);
if(result == NSAlertDefaultReturn) {
[prefs setObject:[NSDictionary
dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],
@"shouldImport", nil] forKey:@"Preferences"];
domain = [prefs
persistentDomainForName:kBetaDomainName];
if([domain objectForKey: @"Reminders"]) {
NSArray *dom = [domain objectForKey: @"Reminders"];
NSEnumerator *enumerator;
id object;
enumerator = [dom objectEnumerator];
while( object = [enumerator nextObject] ) {
[reminderArray addObject:[Reminder
reminderWithDictionary:object]];
}
NSBeep();
result = NSRunAlertPanel(@"Preference Import",
[NSString stringWithFormat:@"Finished importing old Preference file at
%@.\n I will now delete the file.", domainLocation], @"OK", nil, nil);
if(result == NSOKButton) [prefs
removePersistentDomainForName:kBetaDomainName];
}
else {
NSBeep();
NSRunAlertPanel(@"Preference Import Error",
[NSString stringWithFormat:@"The Preference file located at %@ appears
to be corrupted!!", domainLocation], @"OK",nil,nil);
}
}
}
}
}
I hope this helped.
-Esteban
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.