ios - 在 Core Data 中添加新的独立实体是否需要模型版本控制?
<p><p>我想在我的项目中添加一个新的核心数据实体。我是否需要为此添加新的核心数据模型版本,否则它将在现有版本中工作?该实体是独立的,它将与其他先前定义的实体没有任何关系。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>确实,它需要添加一个新的模型版本。但是,添加新实体可以由 <a href="https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmLightweightMigration.html" rel="noreferrer noopener nofollow">lightweight migration</a> 处理。 ,因此至少您不必创建映射模型/编写自定义迁移代码。</p>
<p><strong>更新:</strong></p>
<p>来自关于轻量级迁移的文章:</p>
<blockquote>
<p>In addition, Core Data supports: ... Changing the entity hierarchy</p>
<ul>
<li>You can add, remove, rename entities </li>
<li>You can create a new parent or child entity and move properties up and down the entity hierarchy</li>
<li>You can move entities out of a hierarchy </li>
<li>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</li>
</ul>
</blockquote>
<p>如果你不使用版本控制,你会得到这样的错误:</p>
<blockquote>
<p>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"; }</p>
</blockquote>
<p>这对我来说似乎是使用版本控制的好理由)</p></p>
<p style="font-size: 20px;">关于ios - 在 Core Data 中添加新的独立实体是否需要模型版本控制?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/36261757/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/36261757/
</a>
</p>
页:
[1]