gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:06:03 26 4
gpt4 key购买 nike

我知道您不能将 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/

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