我使用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显示为nil。 我的检索代码是
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"
}