阅读关于 RKManagedObjectStore 的 RestKit
文档后我对 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.
我不明白不可变
托管对象模型是什么意思?我在官方 Core Data
文档和互联网上都找不到有关此主题的任何信息。有人可以解释一下可变
和不可变
托管对象模型之间的区别吗?为什么持久存储协调器的创建会呈现不可变的托管对象模型?哪些功能需要可变的托管对象模型?
提前致谢。
最佳答案
您可以在代码中更改 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 - Core Data 中可变和不可变托管对象模型有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22128225/