Core Data版本更新进行Migration时renaming identifier设置的注意事项
2013-04-20 13:58
239 查看
如果在iOS开发中使用了Core Data,当需要对Model进行更新时(如修改属性名称),需要增加Model版本,并使用在NSPersistentStoreCoordinator创建时,使用相应的Migration Option,具体方法可以参考《How
to Perform a Lightweight Core Data Migration》一文,本文只想提示其中一个需要注意的地方。
假设项目名为Test,则Model名为Test.xcdatamodel,即为原始版本,增加的版本则为Test
2.xcdatamodel,以此类推。
在为修改的的属性名称设置相应的“renaming identifier”时,如果原始版本中属性名为timeStamp,在Test
2.xcdatamodel中修改为when,则需要在Test 2.xcdatamodel中将“renaming
identifier”设置为timeStamp。
如果在第三个版本Test
3.xcdatamodel中又将when修改成了time,则这时候的“renaming
identifier”应该如何设置呢?答案是不用设置,因为在生成Test 3.xcdatamodel时,这个“renaming
identifier”已经被自动复制过来,也就是timeStamp,亦即:
这个“renaming
identifier”必须与原始版本中的属性名一致,而不是上一个版本一致。
在苹果的官方文档中有以下一段文字说明,请参考:
The renaming identifier creates a “canonical name,” so you should set the renaming identifier
to the name of the property in the source model (unless that property already has a renaming identifier). This means you can rename a property in version 2 of a model then rename it again version 3, and the renaming will
work correctly going from version 2 to version 3 or from version 1 to version 3.
to Perform a Lightweight Core Data Migration》一文,本文只想提示其中一个需要注意的地方。
假设项目名为Test,则Model名为Test.xcdatamodel,即为原始版本,增加的版本则为Test
2.xcdatamodel,以此类推。
在为修改的的属性名称设置相应的“renaming identifier”时,如果原始版本中属性名为timeStamp,在Test
2.xcdatamodel中修改为when,则需要在Test 2.xcdatamodel中将“renaming
identifier”设置为timeStamp。
如果在第三个版本Test
3.xcdatamodel中又将when修改成了time,则这时候的“renaming
identifier”应该如何设置呢?答案是不用设置,因为在生成Test 3.xcdatamodel时,这个“renaming
identifier”已经被自动复制过来,也就是timeStamp,亦即:
这个“renaming
identifier”必须与原始版本中的属性名一致,而不是上一个版本一致。
在苹果的官方文档中有以下一段文字说明,请参考:
The renaming identifier creates a “canonical name,” so you should set the renaming identifier
to the name of the property in the source model (unless that property already has a renaming identifier). This means you can rename a property in version 2 of a model then rename it again version 3, and the renaming will
work correctly going from version 2 to version 3 or from version 1 to version 3.
相关文章推荐
- App上架版本号配置的注意事项:CFBundleVersion与CFBundleShortVersionString设置,以及内部检查版本更新
- 不同OpenCV版本和不同VS版本之间进行配置的注意事项
- WINDOWS2003进行WindowsFTP设置的一些注意事项
- CTS、CTS-V、GTS版本更新,及其注意事项
- iOS开发:2017 苹果APP上架更新应用版本注意事项及APP版本迭代步骤方法
- [Android] 使用SVN进行版本控制的注意事项
- WINDOWS2003进行WindowsFTP设置的一些注意事项
- android 发布版本 自动更新 注意事项
- Android Studio2.0 Beta 2版本更新说明及注意事项
- UITableView控件Protocell的Identifier设置 注意事项
- 更新版本注意事项
- Android 版本更新签名冲突的问题以及注意事项,已解决
- 不同OpenCV版本和不同VS版本之间进行配置的注意事项
- 将NLog target设置为RichTextBox的注意事项,NLog版本4.2.1
- iOS App 上架流程-版本更新注意事项
- es注意事项----持续更新
- 关于设置了setMaxAge(0)而浏览器未成功删除Cookie的注意事项
- .NET进行异常处理时的原则注意事项
- 使用Hibernate框架来更新对象的注意事项
- CoreLocation 的基本使用 以及定位 指南针的实现 (附加: 系统版本适配的方法,和后台更新用户位置的方法及注意)