Revert to factory settings: how to do it?
Revert to factory settings: how to do it?
- Subject: Revert to factory settings: how to do it?
- From: "Arthur C." <email@hidden>
- Date: Mon, 11 Dec 2006 19:47:19 +0100
I would like to have a set of preferences stored in the user defaults. These
preferences should have some initial values ("factory settings"), in case
they have not been specified by the user. According to the docs (User
Defaults Programming Topics) this can be done as follows:
+ (void) initialize
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
@"Arthur", @"firstName", @"C.", @"lastName", nil];
[defaults registerDefaults:appDefaults];
}
The keys "firstName" and "lastName" have a binding to the shared user
defaults.
This works OK, but now I want to add a button like 'revert to factory
settings' to restore the initial values. I found that it can be done as
follows:
- (IBAction) revertToFactorySettings: (id) sender
{
[[ NSUserDefaults standardUserDefaults] removeObjectForKey:
@"firstName"];
[[ NSUserDefaults standardUserDefaults] removeObjectForKey: @"lastName"];
}
But in this case I have to cycle through all the keys (what if there are 100
of them?).
Question: is there a way to remove them all at once, *and* restore the old
values?
The following does the first, but the old values are not restored:
- (IBAction) revertToFactorySettings: (id) sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults removePersistentDomainForName: [[NSBundle mainBundle]
bundleIdentifier]];
}
Only after program shutdown and restart, the old values reappear.
Any suggestions?
Thanks in advance,
Arthur C.
_________________________________________________________________
Play online games with your friends with Messenger
http://www.join.msn.com/messenger/overview
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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