若是IOS App 使用到CoreData,而且在上一个版本上有数据库更新(新增表、字段等操做),那在覆盖安装程序时就要进行CoreData数据库的迁移,具体操做以下: html
1.选中你的mydata.xcdatamodeld文件,选择菜单editor->Add Model Version 好比取名:mydata2.xcdatamodel 数据库
2.设置当前版本 app
选择上级mydata.xcdatamodeld ,在inspector中的Versioned Core Data Model选择Current模版为mydata2 spa
3.修改新数据模型mydata2,在新的文件上添加字段及表 .net
4.删除原来的类文件,从新生成下类。 htm
在appdelegate中
blog
- 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.从新编译下程序。 get