我有一个获取的结果 Controller ,它在有谓词时不调用它的委托(delegate)。谓词仅包括具有 events
的 Conversation 对象:
let predicate = NSPredicate(format: "events.@count > 0")
let fetchRequest = Conversation.MR_requestAllSortedBy(
"mostRecentMessage.eventDate",
ascending: false,
withPredicate: predicate)
self.fetchedResultsController = NSFetchedResultsController(
fetchRequest: fetchRequest,
managedObjectContext: MagicalRecordStack.defaultStack()!.context,
sectionNameKeyPath: nil,
cacheName: nil)
self.fetchedResultsController.delegate = self
self.fetchedResultsController.MR_performFetch()
这适用于初始提取,但在添加数据后,它不会调用委托(delegate)。删除谓词后,它会调用委托(delegate)。
还有其他方法吗?
最佳答案
获取谓词只能检查核心数据属性,因为对象本身仍然是错误的。 fetch predicate 不会获取请求实体的所有对象然后过滤它们,它只是获取通过过滤谓词的对象。
作为解决方法,您可以获取事件实体。然后使用部分键按对话分组。
关于ios - NSFetchedResultsController 不使用谓词@count 调用委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34252582/