iOS App升级安装 - CoreData数据库升级
2013-06-19 16:35
417 查看
如果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.重新编译下程序。
转载:http://blog.csdn.net/wang9834664/article/details/8203177
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.重新编译下程序。
转载:http://blog.csdn.net/wang9834664/article/details/8203177
相关文章推荐
- iOS 版本迭代 App升级安装 CoreData数据库升级
- iOS App升级安装 - CoreData数据库升级
- iOS App升级安装 - CoreData数据库升级
- iOS App升级安装 - CoreData数据库升级
- iOS App升级安装 - CoreData数据库升级
- iOS App升级安装 - CoreData数据库升级
- ios已上架的APP更新,使用core data的需要升级core Data数据库,这样做
- IOS APP 升级安装-coredata 的迁移,升级
- iOS CoreData (二) 版本升级和数据库迁移
- CoreData(数据库升级 )版本迁移-iOS App升级安装
- CoreData(数据库升级 )版本迁移-iOS App升级安装
- iOS coredata 数据库升级 时报Can't find model for source store
- CoreData(数据库升级 )版本迁移-iOS App升级安装
- iOS 升级程序中已有的CoreData
- IOS- 企业App"无法升级安装应用程序 因为证书无效"的解决方案
- 升级app时coreData的处理及注意事项
- iOS开发~App初始化或者升级涉及本地数据库迁移的问题
- iOSCoreData数据库:
- iOS:CoreData数据库的使用四(数据库和UITableViewController以及NSFetchedResultsController一起使用)
- (转)iOS App初始化或者升级,涉及本地数据库迁移的问题