升级app时coreData的处理及注意事项
来源:互联网 发布:客服淘宝退换货流程图 编辑:程序博客网 时间:2024/05/21 18:13
如果IOS App 使用到CoreData,并且在上一个版本上有数据库更新(新增表、字段等操作),那在覆盖安装程序时就要进行CoreData数据库的迁移,具体操作如下:(请仔细阅读下面四句话)
1.升级数据库模型:选中你的mydata.xcdatamodeld文件,选择菜单editor->Add Model Version 比如取名:mydata2.xcdatamodel
2.设置当前版本:选择上级mydata.xcdatamodeld ,在inspector中的Versioned Core Data Model选择Current模版为mydata2(inspector界面,即为XCode工作区右侧工具栏)
3.修改新数据模型mydata2,在新的文件上添加,修改或删除字段及表(先增加新的xcdatamodeld文件,在增加字段)
4.删除原来的类文件,重新生成下类。
5.在程序启动时添加如下代码:
NSArray *docs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [docs[0] stringByAppendingPathComponent:@"my.db"]; NSURL *url = [NSURL fileURLWithPath:path]; NSError *error; NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:nil]; NSPersistentStoreCoordinator *persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:options error:&error]) { if (error) { NSLog(@"-------persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType url:%@ error:%@", url, error); } }
0 0
- 升级app时coreData的处理及注意事项
- Coredata版本升级注意事项
- IOS APP 升级安装-coredata 的迁移,升级
- iOS coredata的使用及版本升级
- iOS coredata的使用及版本升级
- WeX5 APP发布及版本升级注意事项
- iOS App升级安装 - CoreData数据库升级
- iOS App升级安装 - CoreData数据库升级
- iOS App升级安装 - CoreData数据库升级
- iOS App升级安装 - CoreData数据库升级
- iOS App升级安装 - CoreData数据库升级
- iOS App升级安装 - CoreData数据库升级
- iOS App升级安装 - CoreData数据库升级
- coreData的升级(迁移)
- Coredata的版本升级
- app升级注意事项
- CoreData的操作(使用, 升级)
- iOS 版本迭代 App升级安装 CoreData数据库升级
- apt-get install的默认安装路径是什么
- 友盟意见反馈——对话框改为单一的用户反馈
- 五只蚂蚁
- 深入剖析printf函数(上):如何不借助第三方库在屏幕上输出"Hello World"?
- 第一次深深感到进步
- 升级app时coreData的处理及注意事项
- Ubuntu 自动安装libsvm
- HDU 3951 Coin Game 简单博弈
- SizeClass With Xcode6(Xcode6 中使用SizeClass布局)
- 深入剖析printf函数(下):---形参列表和格式化输出是如何做到的?
- 第六天
- POJ1178枚举三个地方(所有点都去同一个点)
- HNU Number Guessing
- python 进阶4 笔记