ios - NSManagedObjectContext-保存 : crashes when using NSPredicate

标签 ios core-data nspredicate nsfetchedresultscontroller

我的应用程序中有一个搜索栏和一些创建两个谓词的过滤器。一种用于搜索栏中的字符串,一种用于过滤器 (UISegmentedControl)。

当使用谓词时,我将一个对象插入到上下文中,然后调用 -save: 应用程序崩溃并显示:

CoreData: error: Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  Can't use in/contains operator with collection 1379410732 (not a collection) with userInfo (null)

在保存时: point of crash (SIGABRT)

当不使用谓词时,不会发生这种情况。 我可以在保存过程中以某种方式删除谓词吗?我已经通过获取 NSFetchRequest 进行了尝试,但我无法将其设置回 Controller 。

编辑

我还尝试将 self 添加为 NSManagedObjectContextDidSaveNotification 的观察者,然后使用 -mergeChangesFromContextDidSaveNotification: 就像一个关于 SO 的讨论所建议的那样。这也没有帮助。

最佳答案

我发现了我的问题。这很简单,但是错误消息太困惑了,以至于我没看对地方。

问题是我使用的是[NSPredicate predicateWithFormat:@"number CONTAINS[cd] %@", string]

因此谓词在 NSNumber 上使用了 CONTAINS。令人困惑的部分是谓词在从数据库查询现有数据时起作用。我仍然不明白这部分,但它现在可以使用 == 比较器。

关于ios - NSManagedObjectContext-保存 : crashes when using NSPredicate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18846631/

相关文章:

ios - 某些应用会触发警报,而不是64(本地通知),有什么办法可以管理此警报?

ios - 保存高分辨率资源,以便应用程序知道它可以在 Retina 设备上使用它们

ios - CloudKit复合查询(OR查询)

objective-c - 如何在 arrayController 和 Core Data 上使用谓词

core-data - 核心数据,NSPredicate,ANY键。路径==无

objective-c - 如何在 Objective-C 中查找文件的 32 位 CRC

ios - 线程 1 : exc_bad_instruction(code=exc_i386_invop, 子代码=0x0)错误

iphone - 使用 magicalrecord 替代 fetchedResultsController 代码?

ios - 核心数据 : Insert and delete with To many relationship

swift - 使用未解析的标识符 'NSInsertedObjectsKey'