• 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
Resetting user defaults?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Resetting user defaults?


  • Subject: Resetting user defaults?
  • From: Randall Meadows <email@hidden>
  • Date: Thu, 29 Jan 2004 15:30:54 -0500

[OK, third time's a charm; maybe *this* time I'll remember what address I signed up under...]

I'm trying to implement the functionality to complete reset to a set of factory-supplied defaults. I include a couple of text files that include my factory defaults, which I initially register as defaults, like so:

-----
NSBundle *myBundle = [NSBundle mainBundle];
NSString *defExtensionsFile = [myBundle pathForResource:@"defaultFileExtensions" ofType:@"plist"];
NSString *defFileTypesFile = [myBundle pathForResource:@"defaultFileTypes" ofType:@"plist"];
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
NSArray *defTypes, *defExtensions;

defTypes = [NSArray arrayWithContentsOfFile:defExtensionsFile];
[defaultValues setObject:defTypes forKey:DefFileExts];

defExtensions = [NSArray arrayWithContentsOfFile:defFileTypesFile];
[defaultValues setObject:defExtensions forKey:DefFileTypes];

[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
-----

This is done in my "main" class's +initialize method.

I have a drawer with two lists, populated with the defaults, that the user can use to customize this data, and the changes are saved correctly--the next time the program is run, the customized version is reflected in the list, and I see it's correct in the .plist file. However, upon a request to reset them to the factory settings, I don't get those, but the "old" customized list instead. Here's the latest version of my attempt to reset to factory:

-----
NSBundle *myBundle = [NSBundle mainBundle];
NSString *defExtensionsFile = [myBundle pathForResource:@"defaultFileExtensions" ofType:@"plist"];
NSString *defFileTypesFile = [myBundle pathForResource:@"defaultFileTypes" ofType:@"plist"];
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
NSUserDefaults *defaults;

[NSUserDefaults resetStandardUserDefaults];

[defaultValues setObject:[NSArray arrayWithContentsOfFile:defFileTypesFile] forKey:pdb2cvsDefFileTypes];
[defaultValues setObject:[NSArray arrayWithContentsOfFile:defExtensionsFile] forKey:pdb2cvsDefFileExts];
defaults = [NSUserDefaults standardUserDefaults];
[defaults registerDefaults:defaultValues];

[myFileTypes release];
myFileTypes = [[defaults arrayForKey:pdb2cvsDefFileTypes] mutableCopy];
[myFileTypes retain];

[myFileExtensions release];
myFileExtensions = [[defaults arrayForKey:pdb2cvsDefFileExts] mutableCopy];
[myFileExtensions retain];

[typesTableView reloadData];
[extensionsTableView reloadData];
-----

This and the following code are in my drawer's class. 'myFileTypes' and 'myFileExtensions' are class variables of type NSArray* that are loaded in my drawer's awakeFromNib like so:

-----
myFileTypes = [[[NSUserDefaults standardUserDefaults] arrayForKey:DefFileTypes] mutableCopy];
[myFileTypes retain];
myFileExtensions = [[[NSUserDefaults standardUserDefaults] arrayForKey:DefFileExts] mutableCopy];
[myFileExtensions retain];
-----

These two arrays are manipulated as the user adds and removes entries from the tables, and are the data sources for the tables.

What am I missing that will allow me to remove all customized defaults, and reset them to my factory-supplied defaults?

--
randy

"For those running Apple's Mac OS X or Linux and the various flavors
of Unix, none of this appears to be a problem."
-Stan Orchard, KOMO TV 4 News, Seattle, on the worst virus ever (but
pertains to the worst n viruses; pick your favorite value of n).
_______________________________________________
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.

  • Prev by Date: Calling another window controller
  • Next by Date: Re: Drawing graphics into a view in AppleScript Studio
  • Previous by thread: Calling another window controller
  • Next by thread: manipulating AB data
  • Index(es):
    • Date
    • Thread