问题
我尝试过的
为每种可能的版本组合创建映射模型。这确实有效,但确实很麻烦。
对于版本 14,我需要制作 14 种不同的映射模型。手动。啊。
Code
以下是我为迁移传递的选项:
[persistentStoreCoordinator addPersistentStoreWithType:[self storeType]
configuration:nil
URL:url
options:[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:NO], NSReadOnlyPersistentStoreOption,
nil]
error:&error]){
数据模型
我的数据模型非常复杂,但它是:http://dl.dropbox.com/u/136780/Engine_V2_DataModel.xcdatamodeld.zip http://dl.dropbox.com/u/136780/Engine_V2_DataModel.xcdatamodeld.zip
我现在没有在数据模型中使用任何版本哈希修饰符或重命名标识符。
请参阅这个堆栈溢出问题:多版本升级核心数据迁移 https://stackoverflow.com/questions/1557344/core-data-migration-across-multiple-version-upgrades
基本上,要点是您不需要创建完整的映射模型集。您只需要在每对连续模型之间映射模型,然后您可以通过中间模型逐步将任何旧模型迁移到最新模型。
根据您的商店,性能可能不太好,因为您不是一步完成迁移的。不过,这可能已经足够好了,而且不必创建完整的映射模型集,这可能是值得的。您还可以测试此方法的性能,以确定是否需要在模型的非连续版本之间创建映射。
Marcus Zarra(核心数据爱好者)在这里有代码:http://media.pragprog.com/titles/mzcd/code/ProgressiveMigration/AppDelegate.m http://media.pragprog.com/titles/mzcd/code/ProgressiveMigration/AppDelegate.m
(我正想问这个问题,但感谢 LazyTwitter,Aaron Tuller 向我指出了这个答案:https://twitter.com/tullera/status/57708304683642880 https://twitter.com/tullera/status/57708304683642880 )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)