我正在尝试使用以下代码将 NSDictionary 保存到核心数据。
NSManagedObject *myObject = [NSEntityDescription
insertNewObjectForEntityForName:@"HomeDB"
inManagedObjectContext:context];
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:dataDict forKey:@"pod_casts"];
[archiver finishEncoding];
[archiver release];
[myObject setValue:data forKey:@"podcasts"];
[data release];
[self saveChanges];
并且还尝试使用以下代码从核心数据中检索 NSDictionary
NSEntityDescription *p = [NSEntityDescription entityForName:@"HomeDB" inManagedObjectContext:context];
NSData *data1 = [[NSMutableData alloc] initWithData:[p valueForKey:@"podcasts"]];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data1];
NSDictionary *dbData=[[unarchiver decodeObjectForKey:@"pod_casts"] retain];
[unarchiver finishDecoding];
[unarchiver release];
[data1 release];
这有什么问题?帮我。
我创建了实体“HomeDB”,其中一个属性“podcasts”类型为“Binary”
提前致谢