Еще одна версия той же темы. Я сохранил поддержку Лоуренса Джонстона для дочерних панелей и добавил поддержку i18n / l10n.
// This code is folklore, first created by an unknown person and copied, pasted
// and published by many different programmers, each (hopefully) of whom added
// some improvemrnts. (c) the People of the Earth
- (NSDictionary *)defaultsFromPlistNamed:(NSString *)plistName {
NSString *settingsBundlePath = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
if (!settingsBundlePath) {
NSAssert(settingsBundlePath, @"Could not find Settings.bundle while loading defaults.");
return nil;
}
NSBundle *settingsBundle = [NSBundle bundleWithPath:settingsBundlePath];
if (!settingsBundlePath) {
NSAssert(settingsBundle, @"Could not load Settings.bundle while loading defaults.");
return nil;
}
NSString *plistFullName = [settingsBundle pathForResource:plistName ofType:@"plist"];
if (!plistName) {
NSAssert1(settings, @"Could not find plist '%@' while loading defaults.", plistFullName);
return nil;
}
NSDictionary *settings_dic = [NSDictionary dictionaryWithContentsOfFile:plistFullName];
if (!settings_dic) {
NSAssert1(settings_dic, @"Could not load plist '%@' while loading defaults.", plistFullName);
return nil;
}
NSArray *preferences = [settings_dic objectForKey:@"PreferenceSpecifiers"];
NSAssert1(preferences, @"Could not find preferences entry in plist '%@' while loading defaults.", plistFullName);
NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
for(NSDictionary *prefSpecification in preferences) {
NSString *key = [prefSpecification objectForKey:@"Key"];
if (key) {
id value = [prefSpecification objectForKey:@"DefaultValue"];
if(value) {
[defaults setObject:value forKey:key];
NSLog(@"setting %@ = %@",key,value);
}
}
NSString *type = [prefSpecification objectForKey:@"Type"];
if ([type isEqualToString:@"PSChildPaneSpecifier"]) {
NSString *file = [prefSpecification objectForKey:@"File"];
NSAssert1(file, @"Unable to get child plist name from plist '%@'", plistFullName);
if (file) {
[defaults addEntriesFromDictionary:[self defaultsFromPlistNamed:file]];
}
}
}
return defaults;
}
- (void)registerDefaultsFromSettingsBundle {
[[NSUserDefaults standardUserDefaults] registerDefaults:[self defaultsFromPlistNamed:@"Root"]];
}
Звоните [self registerDefaultsFromSettingsBundle];
с - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
if(x) {NSAssert(x);return nil;}
выглядит глупо, но мне лень что-то с этим делать.