objective-c - 对核心数据对象的引用应该是强引用还是弱引用?

标签 objective-c core-data

我想不出核心数据指的是核心数据之外的任何东西。所以没有办法会出现引用循环。至多核心数据对象指向另一个核心数据对象。

然而,我可能是错的。

Managedobjectcontext 不持有对核心数据的强引用。

这里有指南吗?

最佳答案

Is there any guide here?

这里是 Core Data Programming Guide: Object Lifetime Management 的链接.

它是在 2014 年 7 月更新的,因此它可能有您提出此问题时未发布的新信息。

By default, though, the references between a managed object and its context are weak. This means that in general you cannot rely on a context to ensure the longevity of a managed object instance, and you cannot rely on the existence of a managed object to ensure the longevity of a context. Put another way, just because you fetched an object doesn’t mean it will stay around.

The exception to this rule is that a managed object context maintains a strong reference to any changed

这意味着您对 NSManagedObject 子类(核心数据对象)的引用应该是strong

关于objective-c - 对核心数据对象的引用应该是强引用还是弱引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16479232/

相关文章:

ios - 如何从 NSDictionary (iOS) 中的键/值对中提取值

ios - 核心数据未在 TableView 中获取

ios - 核心数据子有序集

objective-c - NSSet 的 containsObject 和快速枚举哪个更好?

ios - 从 iOS 中的 SQLite DB 得不到结果,但是使用 SQLite 本身得到它们

iphone - 如何阻止 UITextField 响应摇动手势?

ios - 捕获手势识别器开始状态的 Swift 惯用方法

ios - Cocoapods:如何启用 OS_OBJECT_USE_OBJC? (GCD 队列作为适当的 ObjC 对象)

ios - CloudKit/iCloud - 教师/学生场景

iphone - 删除对象核心数据