gpt4 book ai didi

ios - 核心数据中可变和不可变托管对象模型有什么区别?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:07:13 26 4
gpt4 key购买 nike

阅读 RestKit 文档后 RKManagedObjectStore我对 createPersistentStoreCoordinator 方法感到困惑,因为在该方法的描述中有下一个警告:

**Warning:** Creating the persistent store coordinator will
render the managed object model immutable. Attempts to
use functionality that requires a mutable managed object model
after the persistent store coordinator has been created
will raise an application error.

我不明白 immutable 托管对象模型是什么意思?无论是在官方 Core Data 文档中还是在 Internet 上,我都找不到关于这个主题的任何信息。有人可以给我解释一下 mutableimmutable 托管对象模型之间的区别吗?为什么创建持久存储协调器会呈现不可变的托管对象模型?什么功能需要可变的托管对象模型?

提前致谢。

最佳答案

您可以在代码中更改 NSManagedObjectModel(例如添加实体和属性),它被称为可变的。但是一旦您将对象模型附加到持久存储协调器,您就不能再更改它了 - 它已经变得不可变了。

NSManagedObjectModel 的文档中也对此进行了描述:

Editing Models Programmatically Managed object models are editable until they are used by an object graph manager (a managed object context or a persistent store coordinator). This allows you to create or modify them dynamically. However, once a model is being used, it must not be changed. This is enforced at runtime—when the object manager first fetches data using a model, the whole of that model becomes uneditable. Any attempt to mutate a model or any of its sub-objects after that point causes an exception to be thrown. If you need to modify a model that is in use, create a copy, modify the copy, and then discard the objects with the old model.

关于ios - 核心数据中可变和不可变托管对象模型有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22128225/

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