[英]Core Data Transformable Attribute
我正在尝试访问可转换核心数据对象的属性,如下所示:
MainObject *localObject = [self.myArray objectAtIndex:indexPath.row];
TransformableObject *actualObject = localObject.transformableObject;
这很好。 我NSLog
actualObject
并获取正确的键/值对:
actualObject:{
property = "Foo";
property2 = "Apple";
}
但是,当II尝试执行以下操作:
NSLog (@"property:%@",actualObject.property)
我得到-[__NSCFDictionary property]: unrecognized selector sent to instance
我究竟做错了什么? 在我的核心数据类中,我有:
@interface MainObject : NSManagedObject
@property (nonatomic, retain) TransformableObjectClass *transformableObject;
编辑:这是我在核心数据中设置对象的方式
MainObject *event = (MainObject *)[NSEntityDescription insertNewObjectForEntityForName:@"MainObject" inManagedObjectContext:[AppDelegateMy managedObjectContext]];
[event setValuesForKeysWithDictionary:[myArrray objectAtIndex:i]];
-setValuesForKeysWithDictionary:
和Core Data都没有足够神奇的功能来完成这项工作,而无需您付出更多的努力。 现在,您只是在JSON响应中将字典分配给新的托管对象的transformableObject
属性。 如果您尝试保存上下文,我想它可能会失败。 如果要将这些词典转换为实际的TransformableObjectClass
实例,则需要自己进行操作。
如果您的应用程序中包含大量此类内容,则可能需要研究RestKit或其他类似ClassMapper的其他开源JSON到对象映射库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.