iOS App升级安装 - CoreData数据库升级
2015-06-03 13:38
381 查看
如果IOS App 使用到CoreData,并且在上一个版本上有数据库更新(新增表、字段等操作),那在覆盖安装程序时就要进行CoreData数据库的迁移,具体操作如下:
1.选中你的mydata.xcdatamodeld文件,选择菜单editor->Add Model Version 比如取名:mydata2.xcdatamodel
2.设置当前版本
选择上级mydata.xcdatamodeld ,在inspector中的Versioned Core Data Model选择Current模版为mydata2
3.修改新数据模型mydata2,在新的文件上添加字段及表
4.删除原来的类文件,重新生成下类。
在appdelegate中
[html] view
plaincopy
NSDictionary *optionsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],
NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES],
NSInferMappingModelAutomaticallyOption, nil];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeUrl
options:optionsDictionary
error:&error]) {
NSLog(@"failed to add persistent store with type to persistent store coordinator");
}
添加 *optionsDictionary,原来options:nil 改成options:optionsDictionary
5.重新编译下程序。
1.选中你的mydata.xcdatamodeld文件,选择菜单editor->Add Model Version 比如取名:mydata2.xcdatamodel
2.设置当前版本
选择上级mydata.xcdatamodeld ,在inspector中的Versioned Core Data Model选择Current模版为mydata2
3.修改新数据模型mydata2,在新的文件上添加字段及表
4.删除原来的类文件,重新生成下类。
在appdelegate中
[html] view
plaincopy
NSDictionary *optionsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],
NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES],
NSInferMappingModelAutomaticallyOption, nil];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeUrl
options:optionsDictionary
error:&error]) {
NSLog(@"failed to add persistent store with type to persistent store coordinator");
}
添加 *optionsDictionary,原来options:nil 改成options:optionsDictionary
5.重新编译下程序。
相关文章推荐
- 平安科技移动开发二队技术周报(第五期)
- Unity Camera
- 微信开发 创建组织 无权限
- Objective-C中的instancetype和id关键字
- android 设置控件的透明度
- IOS开发—深入理解 GCD(一)
- VDI中Office 2007 AppData漫游后,用户无法保存复制等个性快捷方式
- 启动Android程序:unable to start service Intent {act = com.android.email.ACCOUNT_INTENT}
- CoreData的使用
- 贪吃蛇java小程序
- iOS汉字转码
- Android设计模式系列--观察者模式
- Android 5.0 呼叫流程--呼出
- IOS开发学习笔记039-autolayout 代码实现
- Android中常用的位图操作(View与Bitmap转化、圆角、灰化、提取Alpha、旋转、倒影、剪切……)
- BasicModal - 简单易用的现代 Web App 弹窗
- To show image on Android
- IOS中的线程操作(3)
- Swift项目兼容Objective-c问题汇总
- <<做个截图>>iOS版隐私政策