ios - 在核心数据中添加一个新的独立实体是否需要模型版本控制?

标签 ios objective-c core-data

我想在我的项目中添加一个新的核心数据实体。我是否需要为此添加一个新的核心数据模型版本,或者它将在现有版本中工作?该实体是独立的,并且与之前定义的其他实体没有任何关系。

最佳答案

的确,它需要添加一个新的模型版本。但是,添加新实体可以由 lightweight migration 处理。 ,所以至少您不必创建映射模型/编写自定义迁移代码。

更新:

摘自关于轻量级迁移的文章:

In addition, Core Data supports: ... Changing the entity hierarchy

  • You can add, remove, rename entities
  • You can create a new parent or child entity and move properties up and down the entity hierarchy
  • You can move entities out of a hierarchy
  • You cannot, however, merge entity hierarchies; if two existing entities do not share a common parent in the source, they cannot share a common parent in the destination

如果你不使用版本控制,你会得到这样的错误:

Error Domain=NSCocoaErrorDomain Code=134100 "(null)" UserInfo={metadata={ NSPersistenceFrameworkVersion = 641; NSStoreModelVersionHashes = { TestEntity1 = ; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "F16AD345-02FE-4E94-B11E-3BC337B16568"; "_NSAutoVacuumLevel" = 2; }, reason=The model used to open the store is incompatible with the one used to create the store} with userInfo dictionary { metadata = { NSPersistenceFrameworkVersion = 641; NSStoreModelVersionHashes = { TestEntity1 = ; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "F16AD345-02FE-4E94-B11E-3BC337B16568"; "_NSAutoVacuumLevel" = 2; }; reason = "The model used to open the store is incompatible with the one used to create the store"; }

这对我来说似乎是使用版本控制的一个很好的理由)

关于ios - 在核心数据中添加一个新的独立实体是否需要模型版本控制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36261757/

相关文章:

ios - UITableview 显示 NSMutableArray 中的重复对象

objective-c - NSUrlConnection 不起作用。我没有得到任何回应

ios - 有什么方法可以将系统日志记录到iOS中的单独文件中?

iphone - 计算最近点的有效方法是什么?

ios - 使用 NSFetchedResultsController 返回具有有序关系的对象

objective-c - 许多应用程序在 iO 中使用一个商店

ios - objective-c -按词搜索

html - iOS 将 HTML 实体解码为字符串

iphone - 需要一些关于属性(property)的解释

iOS:从现有单元格以编程方式创建表 "header"