【发布时间】:2012-09-05 21:11:09
【问题描述】:
我正在尝试访问可转换核心数据对象的属性,如下所示:
MainObject *localObject = [self.myArray objectAtIndex:indexPath.row];
TransformableObject *actualObject = localObject.transformableObject;
这很好用。我NSLogactualObject 并得到正确的键/值对:
actualObject:{
property = "Foo";
property2 = "Apple";
}
但是,当我尝试:
NSLog (@"property:%@",actualObject.property)我得到-[__NSCFDictionary property]: unrecognized selector sent to instance
我做错了什么?在我的核心数据类中,我有:
@interface MainObject : NSManagedObject
@property (nonatomic, retain) TransformableObjectClass *transformableObject;
编辑: 这是我在 Core Data 中设置对象的方式
MainObject *event = (MainObject *)[NSEntityDescription insertNewObjectForEntityForName:@"MainObject" inManagedObjectContext:[AppDelegateMy managedObjectContext]];
[event setValuesForKeysWithDictionary:[myArrray objectAtIndex:i]];
【问题讨论】:
-
您最初是如何设置
localObject.transformableObject的值的?您的模型中的属性是如何配置的?actualObject显然是NSDictionary,但你没有给我们足够的信息来推断原因。 -
TransformableObjectClass 是另一个核心数据 NSManagedObject 类。
-
可能是这样,但错误表明实际分配给该属性的是
NSDictionary的实例。那么,它是如何到达那里的呢? -
刚刚添加了一个编辑,我通过 for 循环对 JSON 响应中的每个对象进行了编辑
标签: iphone ios core-data nsdictionary nsmanagedobject