我使用 NSKeyedArchiver 在核心数据下使用以下代码存储 NSDictionary 对象。
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:dict forKey:@"voterExtraInfo"];
[archiver finishEncoding];
[voter setValue:data forKey:@"extraInfo"];
当使用键 @"voterExtraInfo" 检索相同的字典时,NSDictionary 显示为零。我的检索代码是
NSMutableData *data = [[NSMutableData alloc] initWithData:voter.extraInfo];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSDictionary *extraData= [unarchiver decodeObjectForKey:@"voterExtraInfo"];
[unarchiver finishDecoding];
请建议。这是我要存储的字典。
{
"ethnicity": "Hispanic",
"voter_score": "45",
"ipsum": "foo bar"
}