gpt4 book ai didi

iphone - core data : [NSFetchedResultsController -fetchedObjects], 这个方法会反射(reflect)对象的变化吗?

转载 作者:可可西里 更新时间:2023-11-01 04:16:27 26 4
gpt4 key购买 nike

首先我创建了一个 NSFetchedResultsController 和一个 NSFetchRequest 来获取实体“Entity”的所有对象。

然后我插入一个新的 NSManagedObject A,它是“实体”的一个实例,以及编辑 B,它也是“实体”的一个实例。

然后我调用 NSArray *result = [fetchedResultsController -fetchedObjects],结果是 A 和 B 吗?

在整个项目中,我只使用一个 NSManagedObjectContext。

如果我这样做,这在其 Document 中意味着什么? ?

fetchedObjects The results of the fetch.

@property (nonatomic, readonly) NSArray *fetchedObjects Discussion The value of the property is nil if performFetch: hasn’t been called.

The results array only includes instances of the entity specified by the fetch request (fetchRequest) and that match its predicate. (If the fetch request has no predicate, then the results array includes all instances of the entity specified by the fetch request.)

The results array reflects the in-memory state of managed objects in the controller’s managed object context, not their state in the persistent store. The returned array does not, however, update as managed objects are inserted, modified, or deleted.

最佳答案

最后一句的意思

... The returned array does not, however, update as managed objects are inserted, modified, or deleted.

是(基于我的实验):如果你存储对获取对象的引用

NSArray *result = [fetchedResultsController fetchedObjects];

然后 result 引用的这个数组将不会在插入、修改或删除对象时更新。所以重点是“返回的数组不...”。

但是如果你调用

[fetchedResultsController fetchedObjects]

再次,返回值是一个新的对象列表,包括更改。

更准确地说:如果您设置了委托(delegate),则 FRC 会跟踪对托管对象上下文的更改并调用 FRC 委托(delegate)函数。插入/修改/删除对象时不会立即调用委托(delegate)函数,但要么

  • 明确保存上下文时,或者
  • 在运行循环中处理更改通知时。

一旦调用 controllerDidChangeContent:,对 [fetchedResultsController fetchedObjects] 的新调用将返回更新后的对象列表。

关于iphone - core data : [NSFetchedResultsController -fetchedObjects], 这个方法会反射(reflect)对象的变化吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13391934/

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