我想存档一个只包含 NSStrings 的字典,但是当我取消存档时,发生了错误:
[NSKeyedUnarchiver initForReadingWithData:]: NSKeyedUnarchiver 无法解码非密钥存档
我的代码是:
- (IBAction)startArchive:(id)sender {
NSString *path = [self pathForDataFile];
NSMutableDictionary *ageDictionary= [NSMutableDictionary dictionary];
[ageDictionary setValue:@"12" forKey:@"Jack"];
[ageDictionary setValue:@"22" forKey:@"John"];
[NSArchiver archiveRootObject:ageDictionary toFile:path];
}
- (IBAction)unarchive:(id)sender {
NSString *path = [self pathForDataFile];
NSDictionary *rootObject = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
NSLog(@"%@",rootObject);
}