Skip to content

Instantly share code, notes, and snippets.

@pizthewiz
Last active December 10, 2015 17:08
Show Gist options
  • Save pizthewiz/4465585 to your computer and use it in GitHub Desktop.
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
- (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