我想在我的项目中添加一个新的核心数据实体。我是否需要为此添加一个新的核心数据模型版本,或者它将在现有版本中工作?该实体是独立的,并且与之前定义的其他实体没有任何关系。
最佳答案
的确,它需要添加一个新的模型版本。但是,添加新实体可以由 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/