iOS持久化之CoreData(待总结)
2016-01-05 17:58
363 查看
coreData初步认识
根据这片文档可以自己初步建立一个coreData,进行简单的数据的增删改查。
1、新建工程,记得勾选Use Core Data
2、建立好以后可以看到xxx.xcdatamodeld,在这里可以添加实体和实体的属性。需要注意的是:实体名字必须以大写开头。
3、然后新建一个file,记得是NSManagedObject cubclass
4、勾选自己建立的工程
5、勾选建立的实体
6、next以后我们就可以看到建立好的实体是有4个文件,如图一
这里需要注意的是,xcode7以后建立的都是4个,而7以前的是两个,如图二
解释如下:So as you can see now all properties are in a separate file with category (CoreDataProperties). Later if you generate NSManagedObject subclass for the same model Xcode 7 will regenarete only 2 files with category (DBUser+CoreDataProperties.h and DBUser+CoreDataProperties.m)
to update all properties from your model but it will not make any changes to 2 other files (DBUser.h and DBUser.m) so you can use these 2 files to add there some custom methods or properties etc.
In previous version Xcode generated always only 2 files (DBUser.h and DBUser.m) and it put properties there so you could not easily modify these files because your custom implementation was deleted everytime you regenerated your subclasses. Therefore it
was a common practice to manually create a category and put your methods in your category which was oposite to what we can see in Xcode 7. That however had many disadvantages because we had to use a category for implementation of our methods which does not
allow to do certain things and now we can easily modify the main interface and implementation files which allows us to do anything with it. Hurray!
图一
图二
7、
8、增删改查(其实顺序应该是增、查、删或者改)
查询结果
删除后再进行查,查询结果:
改完后的结果:
至此,完成。
这里知识coredata的初步认识,具体的增删改查还需要和自己的项目结合。
原文链接:http://www.jianshu.com/p/337872d95727
根据这片文档可以自己初步建立一个coreData,进行简单的数据的增删改查。
1、新建工程,记得勾选Use Core Data
2、建立好以后可以看到xxx.xcdatamodeld,在这里可以添加实体和实体的属性。需要注意的是:实体名字必须以大写开头。
3、然后新建一个file,记得是NSManagedObject cubclass
4、勾选自己建立的工程
5、勾选建立的实体
6、next以后我们就可以看到建立好的实体是有4个文件,如图一
这里需要注意的是,xcode7以后建立的都是4个,而7以前的是两个,如图二
解释如下:So as you can see now all properties are in a separate file with category (CoreDataProperties). Later if you generate NSManagedObject subclass for the same model Xcode 7 will regenarete only 2 files with category (DBUser+CoreDataProperties.h and DBUser+CoreDataProperties.m)
to update all properties from your model but it will not make any changes to 2 other files (DBUser.h and DBUser.m) so you can use these 2 files to add there some custom methods or properties etc.
In previous version Xcode generated always only 2 files (DBUser.h and DBUser.m) and it put properties there so you could not easily modify these files because your custom implementation was deleted everytime you regenerated your subclasses. Therefore it
was a common practice to manually create a category and put your methods in your category which was oposite to what we can see in Xcode 7. That however had many disadvantages because we had to use a category for implementation of our methods which does not
allow to do certain things and now we can easily modify the main interface and implementation files which allows us to do anything with it. Hurray!
图一
图二
7、
8、增删改查(其实顺序应该是增、查、删或者改)
查询结果
删除后再进行查,查询结果:
改完后的结果:
至此,完成。
这里知识coredata的初步认识,具体的增删改查还需要和自己的项目结合。
原文链接:http://www.jianshu.com/p/337872d95727
相关文章推荐
- iOS持久化之plist(待总结)
- iOS抽屉效果、二级菜单(点击,拖拽滑动)
- iOS中Json解析的四种方法
- iOS - 小方法
- IOS常用宏定义
- IOS中.pch的使用
- iOS开发之使用Xcode和Instruments调试解决iOS内存泄露
- 【iOS开发】从Cocoa框架说开去--Fundation框架系列
- iOS中UDP通信
- iOS中摄像头/相册获取图片,压缩图片,上传服务器方法总结
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 开发之深拷贝与浅拷贝
- iOS开发Item属性总结
- iOS开发,预览和打开文档
- iOS键盘设置透明色
- iOS蓝牙4.0协议简单介绍
- ios 添加字体包
- iOS开发系列--无限循环的图片浏览器
- iOS常用捕获异常及处理方法
- cocoa 之 KVO