Last active
December 10, 2015 17:08
-
-
Save pizthewiz/4465585 to your computer and use it in GitHub Desktop.
sift through Settings.bundle for default values and register as user defaults. makes use of NSArray category from Mantle: https://github.com/github/Mantle/blob/master/Mantle/NSArray%2BMTLHigherOrderAdditions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { | |
// set default preferences from Settings.bundle | |
NSURL* plistURL = [[[NSBundle mainBundle] URLForResource:@"Settings" withExtension:@"bundle"] URLByAppendingPathComponent:@"Root.plist"]; | |
if (!plistURL) { | |
NSLog(@"ERROR - failed to find 'Settings.bundle/Root.plist' within main bundle"); | |
} else { | |
NSArray* specifiers = [NSDictionary dictionaryWithContentsOfURL:plistURL][@"PreferenceSpecifiers"]; | |
NSDictionary* defaults = [specifiers mtl_foldLeftWithValue:[NSMutableDictionary dictionary] usingBlock:^id(NSMutableDictionary* left, NSDictionary* right) { | |
if (right[@"Key"] && right[@"DefaultValue"]) { | |
left[right[@"Key"]] = right[@"DefaultValue"]; | |
} | |
return left; | |
}]; | |
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults]; | |
} | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment