ios - 核心数据中的过滤器与 NSPredicate

标签 ios objective-c swift core-data

我知道您不能将 coredata 视为关系数据库,因为它是一个对象图(如果我错了请纠正我)。因此,当您使用谓词调用提取请求时,我对内存中发生的事情有点迷茫。

  1. 是先将整个实体加载到 ManageObjectContext,然后在谓词的帮助下进行过滤,还是直接像关系数据库一样进行过滤(像选择一样直接从表中选取值查询在关系数据库中有效)??

  2. 如果它将整个实体加载到内存中,为什么不使用“filter”而不是“NSPredicate”

如果能提供适当的 Apple 引用答案,我们将不胜感激。

最佳答案

来自 Persistent Store Types and Behaviors在核心数据编程指南中(添加了重点):

Fetching differs somewhat according to the type of store. In the XML, binary, and in-memory stores, evaluation of the predicate and sort descriptors is performed in Objective-C with access to all Cocoa functionality, including the comparison methods on NSString.

The SQLite store, on the other hand, compiles the predicate and sort descriptors to SQL and evaluates the result in the database itself. This is done primarily for performance, ...

您可以通过启用 Core Data 调试来验证这一点。设置

-com.apple.CoreData.SQLDebug 3
-com.apple.CoreData.Logging.stderr 1  

作为环境变量,您将在执行时看到 SQLite 语句。

关于ios - 核心数据中的过滤器与 NSPredicate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62994237/

相关文章:

iOS 推送通知不起作用

ios - 无法立即呈现图像选择器

ios - 在 instantiateViewControllerWithIdentifier 之后 dealloc

实现另一个具有共享关联类型的协议(protocol)的 Swift 协议(protocol)扩展

ios - 即使已取消并设置为Nil,Swift iOS -DispatchWorkItem仍在运行

ios - Xmpp Ios停止双向订阅

android - 适用于 iOS、Android 和 WP7 的替代移动商务平台

objective-c - 淡出 NSScrollView 的顶部和底部

ios - 表格 View 单元格中的阴影层越界

swift - 将 TapGestureRecognizer 添加到 TextField