gpt4 book ai didi

ios - Not Acceptable 一对一关系的值类型 : desired type = NSManagedObject; given type = NSManagedObject;

转载 作者:行者123 更新时间:2023-12-01 16:04:46 24 4
gpt4 key购买 nike

我正在尝试将对象添加到“一对一”关系中:

//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"];

我收到以下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException',reason:'Unacceptable type of value for to-one relationship: property ="fkServerUpdatesToAuthors"; desired type = NSManagedObject; given type =NSManagedObject; value = (entity: Authors; id: 0x74a2290



起初我以为这是因为我试图分配持久对象和临时对象之间的关系,但是当我在1.和2.之间添加保存时,仍然出现相同的错误。

Note:
I haven't created any associated sub-classes for NSManagedObject. The relationship setup is: fkServerUpdatesToAuthors (to-one) in ServerUpdates entity INVERSE RELATIONSHIP WITH fkAuthorsToServerUpdates (to-many) in Authors entity.



非常感谢任何帮助!

最佳答案

我删除了 ServerUpdates 的 CoreData 实体,重新构建它并开始工作。

如果其他人遇到同样的问题:我认为原因是将错误的 NSManagedObject 分配给 fkServerUpdatesToAuthors 关系属性。它期待一个“作者”NSManagedObject(如关系的“目的地”字段中所定义),但我必须传递一些不同的东西 - 例如“书籍”(反之亦然)。

错误消息不清楚,因为我抽象为使用 NSManagedObject 访问对象(而不是 Authors 或 Books 子类),因此对于编译器,Authors 和 Books NSManagedObjects 都只是 NSManagedObjects。

总之,检查您是否将正确的 NSManagedObject 发送到“目标”字段中定义的关系。

希望这对 future 的人有所帮助。

关于ios - Not Acceptable 一对一关系的值类型 : desired type = NSManagedObject; given type = NSManagedObject;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16711160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com