gpt4 book ai didi

ios - 无法删除其他上下文中的对象

转载 作者:行者123 更新时间:2023-11-29 10:39:32 24 4
gpt4 key购买 nike

3 个月以来,我一直面临这个问题。我进行了大量搜索并阅读了相关文档并访问了许多论坛,但找不到可行的解决方案。删除对象时出现典型的 NSManagedObject 错误。 NSManagedObjectContext 无法删除其他上下文中的对象。

我试图绕过并尝试使用其 NSManagedObject ID 删除对象,但无济于事。

  NSManagedObjectID *findingsSurveyDataItemApiId = [findingsSurveyDataItemApi objectID];
[self.managedObjectContext deleteObject:[self.managedObjectContext objectWithID:findingsSurveyDataItemApiId]];

谁能告诉我为什么上面的解决方案仍然不起作用?

PS:我在应用程序中有两个托管对象上下文。

最佳答案

我想这可能是来自 Core Data 的误导性错误消息。根据 docs,如果您要删除的对象尚未保存到持久存储中,objectWithID 将不会返回有效对象。 :

The data in the persistent store represented by objectID is assumed to exist—if it does not, the returned object throws an exception when you access any property (that is, when the fault is fired).

改用 existingObjectWithID:error: 并在尝试删除之前检查它是否返回非 nil 对象。

关于ios - 无法删除其他上下文中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25198697/

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