【发布时间】:2013-05-23 10:10:48
【问题描述】:
我正在尝试将对象添加到“一对一”关系:
//1. I create the temporary object for the ServerUpdates entity
NSManagedObject *updateObj = [NSEntityDescription insertNewObjectForEntityForName:@"ServerUpdates" inManagedObjectContext:self.managedObjectContext];
//2. I make sure that obj is in the same context (note: I get obj from fetch)
obj = [self.managedObjectContext objectWithID:[obj objectID]];
//3. I then try to add the object to the key - and this is where we get the error
[updateObj setValue:obj forKey:@"fkServerUpdatesToAuthors"];
我收到以下错误:
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'一对一关系的值类型不可接受:属性=“fkServerUpdatesToAuthors”;所需类型 = NSManagedObject;给定类型 =NSManagedObject; value = (entity: Authors; id: 0x74a2290
起初我以为这是因为我试图在持久对象和临时对象之间分配关系,但是当我在 1. 和 2. 之间添加保存时,我仍然遇到了同样的错误。
注意:
我还没有为 NSManagedObject 创建任何关联的子类。关系设置为:ServerUpdates 实体中的 fkServerUpdatesToAuthors (to-one) INVERSE RELATIONSHIP WITH fkAuthorsToServerUpdates (to-many) 在 Authors 实体中。
非常感谢任何帮助!
【问题讨论】:
标签: ios objective-c core-data nsmanagedobject