I'm working through the new Cocoa Programming book and one of the exercises is to add a button for the user to reset their preferences (drop any changes made to their NSUserDefaults and revert to the factory defaults).
In looking at the docco for NSUserDefaults, I see there's a class method "resetStandardUserDefaults" which sounds like it might do what I want... until I read the description: "Synchronizes any changes made to the shared user defaults object and releases it from memory." I'm not sure what the point of that is, but it doesn't seem like it does what I want. I tried it in a bit of code, but nothing actually changed:
I'm guessing that just saves the changed prefs out to disk, and then the setColor method reads in the (changed) stuff again. So nothing was actually reset.
Right now I'm thinking the only way to reset the prefs will be to loop through all of the keys in the standard user defaults object and set each one back to whatever the initial value was. Is that the correct way, or am I misunderstanding what resetStandardUserDefaults does?
In looking at the docco for NSUserDefaults, I see there's a class method "resetStandardUserDefaults" which sounds like it might do what I want... until I read the description: "Synchronizes any changes made to the shared user defaults object and releases it from memory." I'm not sure what the point of that is, but it doesn't seem like it does what I want. I tried it in a bit of code, but nothing actually changed:
Code:
[NSUserDefaults resetStandardUserDefaults];
[colorWell setColor:[self tableBgColor]];
[checkbox setState:[self emptyDoc]];
I'm guessing that just saves the changed prefs out to disk, and then the setColor method reads in the (changed) stuff again. So nothing was actually reset.
Right now I'm thinking the only way to reset the prefs will be to loop through all of the keys in the standard user defaults object and set each one back to whatever the initial value was. Is that the correct way, or am I misunderstanding what resetStandardUserDefaults does?