我正在尝试将对象添加到“一对一”关系中:
//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; 价值=(实体:作者;id:0x74a2290
起初我以为这是因为我试图在持久对象和临时对象之间分配关系,但是当我在 1. 和 2. 之间添加保存时,我仍然得到同样的错误。
注意:
我没有为 NSManagedObject 创建任何关联的子类。关系设置为:ServerUpdates 实体中的 fkServerUpdatesToAuthors(一对一)与 Authors 实体中的 fkAuthorsToServerUpdates(一对多)的反向关系。
非常感谢任何帮助!