ios - Core Data 中可变和不可变托管对象模型有什么区别?

标签 ios objective-c cocoa-touch core-data restkit

阅读关于 RKManagedObjectStoreRestKit 文档后我对 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/

相关文章:

ios - 平滑我的滚动 TouchesMoved

ios - 出现错误,因为在执行 [FMDatabaseQueue inDatabase :]? 之后至少有一个打开的结果集

iphone - UIAlertView 导致 iOS SDK 6.0 崩溃

objective-c - performSelectorOnMainThread 调用何时执行?

ios - tableView reloadData 失去文本字段焦点

cocoa - 小数点前不能有零

ios - 如何在 UITableView 或 UICollectionView 中使用变量 UIStackView?

ios - iOS 8.0 中的 UISearchBar barTintColor clearColor 错误

ios - User-Agent 在 NSMutableURLRequest 中没有改变

cocoa-touch - UIActivityViewController : Activity-Items configuration