Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 21st, 2012  |  syntax: None  |  size: 1.29 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. - (void)loadDefaultSettings
  2. {
  3.         NSMutableDictionary *defaults = [NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default-Settings" ofType:@"plist"]];
  4.        
  5.         // other setup...
  6.        
  7.         [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithDictionary:defaults]];
  8. }
  9.  
  10. - (void)resetDefaultSettings
  11. {
  12.         NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  13.  
  14.         NSString *bundleIdentifer = [[NSBundle mainBundle] bundleIdentifier];
  15.         NSDictionary *persistentDomain = [userDefaults persistentDomainForName:bundleIdentifer];
  16.         for (NSString *key in [persistentDomain allKeys]) {
  17.                 [userDefaults removeObjectForKey:key];
  18.         }
  19. }
  20.  
  21.  
  22. - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
  23. {
  24.         DebugLog(@"%s called", __PRETTY_FUNCTION__);
  25.        
  26.         if ([NSEvent modifierFlags] == NSShiftKeyMask) {
  27.                 NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"DefaultsResetText", nil) defaultButton:NSLocalizedString(@"Cancel", nil) alternateButton:NSLocalizedString(@"OK", nil) otherButton:nil informativeTextWithFormat:NSLocalizedString(@"DefaultsResetDescription", nil)];
  28.                 NSInteger returnCode = [alert runModal];
  29.                 if (returnCode == NSAlertAlternateReturn) {
  30.                         [self resetDefaultSettings];
  31.                 }
  32.         }
  33.        
  34.         [self loadDefaultSettings];
  35.  
  36.         // other setup...
  37. }