ios - 核心数据 : Can't modify an immutable model

标签 ios core-data

这是我的代码

__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

NSArray *entities = [__managedObjectModel entities];
for (NSEntityDescription *entityDesc in entities)
{
    NSLog(@"TWEAK");
    [entityDesc setProperties:[entityDesc properties]];
}

此抛出异常“NSInternalInconsistencyException”,原因:“无法修改不可变模型。”上

不知道为什么?在我看来,这应该是可编辑的,不是吗?

最佳答案

官方doc表示它是可编辑的直到托管对象模型关联到持久存储协调器

因此:

  1. 如果您在问题中未引用的代码中将妈妈分配给了 psc,则如文档中所述。
  2. 如果您真的只是运行上面粘贴的代码,那么这是 Apple 的一个错误,无论是库还是其文档。您应该提交错误报告。

无论如何,CoreData 数据库文件与固定模型相关联,因此通常您不能只调整模型中的实体描述并将其用于保存的 CoreData 文件。您希望通过调整实体描述来实现什么目的?

关于ios - 核心数据 : Can't modify an immutable model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8111332/

相关文章:

ios - Instruments 中的 AutoLayout 模板在哪里?

ios - 如何在 UIActionSheet 中呈现 UIImagePickerViewController?

ios - 将 xcdatamodel 重新添加到build设置中

ios - 路径上的数据模型编译失败

ios - iPhone 和核心数据 - 删除 NSManagedObject?

ios - contentOffsetForScrollingToRowAtIndexPath :atScrollPosition:usingPresentationValues

ios - Swift、iOS15、UIKit、CollectionView header 问题

ios - 基于时间执行功能

swift - 在遍历已完成的 NSManagedObject 时如何应用谓词?

ios - 删除核心数据数据库,并在更新时重新创建它