Skip to content

Instantly share code, notes, and snippets.

@chockenberry
Created October 3, 2011 21:18
Show Gist options
  • Save chockenberry/1260280 to your computer and use it in GitHub Desktop.
Save chockenberry/1260280 to your computer and use it in GitHub Desktop.
- (void)loadDefaultSettings
{
NSMutableDictionary *defaults = [NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default-Settings" ofType:@"plist"]];
// other setup...
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithDictionary:defaults]];
}
- (void)resetDefaultSettings
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *bundleIdentifer = [[NSBundle mainBundle] bundleIdentifier];
NSDictionary *persistentDomain = [userDefaults persistentDomainForName:bundleIdentifer];
for (NSString *key in [persistentDomain allKeys]) {
[userDefaults removeObjectForKey:key];
}
}
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
DebugLog(@"%s called", __PRETTY_FUNCTION__);
if ([NSEvent modifierFlags] == NSShiftKeyMask) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"DefaultsResetText", nil) defaultButton:NSLocalizedString(@"Cancel", nil) alternateButton:NSLocalizedString(@"OK", nil) otherButton:nil informativeTextWithFormat:NSLocalizedString(@"DefaultsResetDescription", nil)];
NSInteger returnCode = [alert runModal];
if (returnCode == NSAlertAlternateReturn) {
[self resetDefaultSettings];
}
}
[self loadDefaultSettings];
// other setup...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment