gpt4 book ai didi

iphone - insertNewObjectForEntityForName : inManagedObjectContext: returning NSNumber bug?

转载 作者:行者123 更新时间:2023-12-03 19:23:15 26 4
gpt4 key购买 nike

我对 CoreData 比较熟悉,并且已经使用它好几年了,几乎没有任何困难。突然间,我被一个错误弄得目瞪口呆。对于我的一生,我无法弄清楚为什么

insertNewObjectForEntityForName:inManagedObjectContext:

突然返回某种奇怪的 NSNumber 实例。 GDB 表示返回的对象是 NSManagedObject 的正确自定义子类,但是当我去打印 NSManagedObject 本身的描述时,出现以下错误:

*** -[NSCFNumber objectID]: unrecognized selector sent to instance 0x3f26f50

更奇怪的是,我可以使用 setValue:forKey: 设置一些关系和属性,一切都很好。但是当我尝试设置一次特定关系时,出现此错误:

*** -[NSCFNumber entity]: unrecognized selector sent to instance 0x3f26f50

有人遇到过类似的事情吗?我尝试清理所有目标,重新启动所有内容,甚至将模型更改为有问题的关系是一对一而不是一对多。没有任何区别。

最佳答案

我之前遇到过“无法识别的选择器发送到实例 0x...”错误,当时我期望位于内存地址“指针”的对象已被其他内容替换。采取这种情况:

NSAutoReleasePool *pool = [[NSAutoReleasePool alloc] init];NSString *someString = [NSString stringWithString:@"some string"]; // autoreleased object returned[pool drain];[pool release];/*some other code executes*/// since the string behind the someString variable has been autoreleased at this point, the memory that someString points to may be occupied by some other data type.  the following may through an EXC_BAD_ACCESS error, or it may try and execute the selector on whatever is occupying that memory spaceint stringLength = [someString length];

这个例子非常简单,我的语义可能有点偏离,但是这有可能是你的例子中以更复杂的方式发生的事情吗?也许可以尝试:

[[NSEntityDescription insertNewObjectForEntityForName:@"entityName" inManagedObjectContext:managedObjectContext] retain]

看看会发生什么?

关于iphone - insertNewObjectForEntityForName : inManagedObjectContext: returning NSNumber bug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2739724/

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