xcdatamodel的多个版本是否意味着我们需要多个xcmappingmodel文件?
我有多个版本的 xcdatamodel 文件:
app1.0.xcdatamodel
app1.1.xcdatamodel
app1.2.xcdatamodel (current)
这是否意味着我需要 xcmappingmodel 文件的多个组合来涵盖所有升级方案?
app1.0_to_app1.1.xcmappingmodel (had this already)
app1.1_to_app1.2.xcmappingmodel (is it iterative?)
app1.0_to_app1.2.xcmappingmodel (too much?)
谢谢!
I have multiple versions of xcdatamodel files:
app1.0.xcdatamodel
app1.1.xcdatamodel
app1.2.xcdatamodel (current)
Does this mean I need multiple combinations of xcmappingmodel files to cover all upgrade scenarios?
app1.0_to_app1.1.xcmappingmodel (had this already)
app1.1_to_app1.2.xcmappingmodel (is it iterative?)
app1.0_to_app1.2.xcmappingmodel (too much?)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
progressivelyMigrateURL 是一个很好的示例,但我认为您实际上并不需要它,因为只要您开发应用程序,就会出现文档的版本,因此每次您需要的映射模型数量与数据模型的受支持版本减一而不是更多(例如,您不需要 app1.0_to_app1.1.xcmappingmodel,因为 1.1 版本不再是最新版本)。每次创建新版本时,您只需要更正您拥有的每个映射模型中的目标模型,并在需要时添加一个目标模型,也许您需要生成新版本并删除旧版本。事实上,您可能会注意到,一个阶段的迁移(与渐进式迁移相比,不会强迫您创建更多映射模型)在运行时要快得多。
您也不需要为琐碎的情况创建映射模型,也不需要使用轻量级迁移(如果具体情况需要无法在运行时生成的映射模型,请使用默认迁移过程(当然您需要将其放在您的应用程序中) Bundle)) 或借助 NSMappingModel 类的 inferredMappingModelForSourceModel:destinationModel:error: 方法在运行时创建的映射模型进行迁移,然后根据需要在代码中进行自定义(您将需要触发据我所知,在这种情况下,通过调用 NSMigrationManager 实例的 migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error: 方法手动迁移)。
祝你好运!
The progressivelyMigrateURL is a great sample, but I don't think you actually need it as versions of your document appear as long as you develop the application so every time you need as many mapping models as the count of supported versions of the data model minus one and not more (for example you don't need the app1.0_to_app1.1.xcmappingmodel as 1.1 version is not the latest version any more). Every time when you create a new version you need just to correct a target model in every mapping model you have and add one more if needed, maybe you will need to generate new ones and remove old ones though. The fact is that migration in one stage (which doesn't force you to create more mapping models compared to the progressive one) is much much faster in runtime as you may notice.
You also don't need to create mapping models for trivial cases and either use a Lightweight Migration (use The Default Migration Process instead if concrete situation needs a mapping model which cannot be generated in runtime (of course you need to have it in your app bundle)) or migrate with a help of the mapping model created in runtime with the help of the inferredMappingModelForSourceModel:destinationModel:error: method of the NSMappingModel class and then customized in code if needed (you will need to trigger migration manually in this case by calling the migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error: method of NSMigrationManager instance as far as I understand).
Good luck!
Core Data 要求您创建一个映射模型,以从数据存储的当前版本到数据存储的最新版本。这意味着您需要制作一个从 v1 -> v1 开始的版本。 v2 和 v2 -> v3 和 v1 -> v3。
来自核心数据版本控制和迁移指南
正如本 Apple 文档中所讨论的
核心数据映射
Core Data requires that you create a mapping model to go from the current version of the data store to the latest version of the data store. This means that you will need to make one that goes from v1 -> v2 and v2 -> v3 and v1 -> v3.
From Core Data Versioning and Migration Guide
As discussed in this Apple Document
Core Data Mapping
您可以实施渐进式数据迁移。在此处查找 progressivelyMigrateURL http://media .pragprog.com/titles/mzcd/code/ProgressiveMigration/AppDelegate.m
You could implement progressive data migration. Look for progressivelyMigrateURL in here http://media.pragprog.com/titles/mzcd/code/ProgressiveMigration/AppDelegate.m