I have an iOS application with a settings.bundle that handles various settings for my application with Switch toggle
. I set default values in my root.plist file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//< Register Defaults
NSString *settingsBundlePath = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
NSBundle *settingsBundle = [NSBundle bundleWithPath:settingsBundlePath];
NSString *rootPlistPath = [settingsBundle pathForResource:@"Root" ofType:@"plist"];
NSDictionary *settingsDict = [[NSDictionary alloc] initWithContentsOfFile:rootPlistPath];
NSArray *settingsItems = [settingsDict objectForKey:@"PreferenceSpecifiers"];
NSMutableDictionary *defaultDict = [NSMutableDictionary new];
for (NSDictionary *itemDict in settingsItems) {
if ([itemDict objectForKey:@"DefaultValue"]) {
[defaultDict setObject:[itemDict objectForKey:@"DefaultValue"] forKey:[itemDict objectForKey:@"Key"]];
}
}
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultDict];
//< Following Code
}