iOS 使用CoreData时该注意的问题之一
来源:互联网 发布:怎么看卖家淘宝网址 编辑:程序博客网 时间:2024/05/20 05:07
出现过的问题:在使用CoreData做数据缓存的时候,在Model里面增加了两个字段(Attribute),运行直接崩了。
其实,不仅仅是在Model里面增加字段,包括对数据库表(Entity)或者表中的字段(Attribute)直接进行了增删改的操作,都会崩了。
解决方法:
(1)选中你的model.xcdatamodeld文件,选择菜单editor->Add Model Version 比如取名:model2.xcdatamodel
(2)设置当前版本
选择上级model.xcdatamodeld ,在inspector中的Versioned Core Data Model选择Current模版为model2
(3)修改新数据模型model2,在新的文件上添加字段及表
(4)把原来的(绿色部分代码)改为下面的
增删改之前: [store addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[NSURL fileURLWithPath:storeUrl options:nil error:nil];
//添加字段之后要这么写
增删改之后: NSDictionary *optionsDictionary = [NSDictionarydictionaryWithObjectsAndKeys:[NSNumbernumberWithBool:YES],
NSMigratePersistentStoresAutomaticallyOption, [NSNumbernumberWithBool:YES],
NSInferMappingModelAutomaticallyOption,nil];
if (![storeaddPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:[NSURLfileURLWithPath:storeUrl
options:optionsDictionary
error:nil]) {
NSLog(@"failed to add persistent store with type to persistent store coordinator");
}
- iOS 使用CoreData时该注意的问题之一
- IOS适配该注意的问题
- IOS - CoreData的使用
- iOS CoreData的使用
- 使用CHtmlView需要注意的问题之一
- CoerDate的使用之一:coreData的介绍
- coreData 存储数据模型应该注意的问题
- ios中的coredata的使用
- IOS CoreData的初始化使用
- ios中的coredata的使用
- ios中的coredata的使用
- ios中的coredata的使用
- iOS CoreData的基本使用
- ios中coredata的使用
- ios中的coredata的使用
- ios中的coredata的使用
- ios中的coredata的使用
- ios中的coredata的使用
- json表单序列化
- CRC循环冗余检验算法
- GET与POST比较(数据大小、数据类型、传送形式)
- IOS核心动画高级二:寄宿图
- 出国开会总结,学生,初次出国参加学术会议
- iOS 使用CoreData时该注意的问题之一
- 网页中怎么插入flash的代码
- Gradle个人笔记(未完)
- MapReduce Shuffle过程分析
- Jmeter(一)脚本录制工具badboy和Jmeter基本使用
- 快速制作deb包
- 对于“前端按需加载资源”的经验总结
- 如何确保外包不被坑,项目不烂尾,架构是核心
- 表关联关系