我将尝试使用
谢谢
保存代码:
而且键是(null):
NSUserDefaults
保存NSMutableDictionary
。我在stackoverflow上阅读了许多相关帖子...我也找到了一个可行的选项; 但不幸的是,它只起作用了一次,然后就开始保存(null)。
有人有什么提示吗?谢谢
保存代码:
[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:dictionary] forKey:@"Key"];
[[NSUserDefaults standardUserDefaults] synchronize];
加载代码:
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
NSData *data = [[NSUserDefaults standardUserDefaults]objectForKey:@"Key"];
dictionary = [NSKeyedUnarchiver unarchiveObjectWithData:data];
向 NSMutableDictionary
添加对象的代码:
[dictionary setObject:[NSNumber numberWithInt:0] forKey:@"Key 1"];
[dictionary setObject:[NSNumber numberWithInt:1] forKey:@"Key 2"];
[dictionary setObject:[NSNumber numberWithInt:2] forKey:@"Key 3"];
将值输出到 NSLog() 的代码:
for (NSString * key in [dictionary allKeys]) {
NSLog(@"key: %@, value: %i", key, [[dictionary objectForKey:key]integerValue]);
}
而且键是(null):
NSLog(@"%@"[dictionary allKeys]);