我试图解开一个字典并将其存储在用户默认值中。该字典包含字符串和数字/布尔。iOS用户默认 - 我需要使用setInteger:forKey:如果我打算从默认使用integerForKey检索原语:?
在我的使用情况下,我使用检索和intergerForKey:
boolForKey:
对于这种使用情况的数字,我是否需要使用setInteger存储在用户的默认号码:forKey:,或者我可以使用通用的setObject:forKey:和给它一个数字*?
- (void)configureWithJSON:(NSDictionary *)conf {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSNumber *timeout = (NSNumber *)conf[@"timeout"];
if(timeout != nil) {
[defaults setInteger:[timeout intValue] forKey:@"timeout"];
}
//OR
[defaults setObject:timeout forKey:@"timeout"];
}
//then, in code I use
[defaults boolForKey:@"timeout"]?
我的意思是,该词典是基于JSON文件有整数和布尔值。字典本身会将它们包裹在对象中。如果在存储之前需要明确拆包,我很感兴趣。 – 2014-10-01 15:11:37