• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Revert to factory settings: how to do it?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Revert to factory settings: how to do it?
      • From: "R. Tyler Ballance" <email@hidden>
  • Prev by Date: Re: MacSoftware update causes my application to hang
  • Next by Date: Re: Revert to factory settings: how to do it?
  • Previous by thread: Re: NSArrayController, add:, default values
  • Next by thread: Re: Revert to factory settings: how to do it?
  • Index(es):
    • Date
    • Thread