iOS 10 (X8)上CoreData的使用(包含创建工程时未添加CoreData)
1.在创建工程时未添加CoreData,后期想要使用CoreData则要在工程Appdelegate.h文件中添加CoreData库和CoreData中的通道类(用来管理类实例和CoreData之间的所有操作)和保存到CoreData文件的方法.
2.添加完这些后去创建.xcdatamodeld文件
3.填写创建文件的名称(建议与工程名字一致后面添加CoreData)
4.文件创建完成后就可以像以前一样去创建对应实体文件和添加实体的属性了.
5.添加完实体后生成对应的实体类文件
6.创建完对应的实体类文件后回到Appdelegate.m中去实现添加的方法和实例
1.首先在Appdelegate.m的- (void)applicationWillTerminate:(UIApplication *)application;中调用下保存的方法.- (void)applicationWillTerminate:(UIApplication *)application {// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. [self saveContext]; }2.然后实现通道类和保存的方法.#pragma mark - Core Data stack@synthesize persistentContainer = _persistentContainer;- (NSPersistentContainer *)persistentContainer {// The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. @synchronized (self) {if (_persistentContainer == nil) {_persistentContainer = [[NSPersistentContainer alloc] initWithName:@"LotterSelectCoreData"];[_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {if (error != nil) {// Replace this implementation with code to handle the error appropriately.// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development./*Typical reasons for an error here include:* The parent directory does not exist, cannot be created, or disallows writing.* The persistent store is not accessible, due to permissions or data protection when the device is locked.* The device is out of space.* The store could not be migrated to the current model version.Check the error message to determine what the actual problem was.*/NSLog(@"Unresolved error %@, %@", error, error.userInfo);abort();}}];}}return _persistentContainer; }#pragma mark - Core Data Saving support- (void)saveContext {NSManagedObjectContext *context = self.persistentContainer.viewContext;NSError *error = nil;if ([context hasChanges] && ![context save:&error]) {// Replace this implementation with code to handle the error appropriately.// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.NSLog(@"Unresolved error %@, %@", error, error.userInfo);abort();} }
7.至于新版Xcode 中coredata的使用在下篇博文中会有介绍.
转载于:https://www.cnblogs.com/xiangnizhidao/p/6029381.html
iOS 10 (X8)上CoreData的使用(包含创建工程时未添加CoreData)相关推荐
- ios view 切上部分圆角_IOS开发入门之给view添加圆角并指定位置
本文将带你了解IOS开发入门之给view添加圆角并指定位置,希望本文对大家学IOS有所帮助. ios中给view添加圆角并指定位置 在ios开发中,为了有个不错的UI交互效果,我们经常会用到为视图添加 ...
- CoreData 从入门到精通 (一) 数据模型 + CoreData 栈的创建
概述 CoreData 是 Cocoa 平台上用来管理模型层数据和数据持久化的一个框架,说简单点,就是一个数据库存储框架.CoreData 里相关的概念比较多,而且初始化也非常繁琐,所以对初学者的学习 ...
- ios 开发账号 退出协作_如何在iOS 10中的Notes上进行协作
ios 开发账号 退出协作 iOS' Notes app provides a convenient way to remember the great ideas you come up with ...
- Julia的安装与配置详解(包含在Ubuntu 18.04和Windows 10系统上Julia的安装)
Julia的安装与配置详解((包含在Ubuntu 18.04和Windows 10系统上Julia的安装) Julia的安装 使用二进制文件安装Julia 在Ubuntu上安装Julia 在Windo ...
- iOS 10隐藏APP图标 – 让隐私的APP从桌面上消失
因为隐私方面的原因,我们有需求隐藏iOS系统中的APP,这里指的是所有的APP,而且是隐藏不是删除,也就是隐藏后还能正常使用,一般用第三方APP启动.想要GET这个技能吗,跟我来,一步都不能错哦!下面 ...
- iOS:Github上的开源项目集合
转载地址:http://blog.csdn.NET/hbblzjy/article/details/52083919 下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. ...
- 活久见的重构 - iOS 10 UserNotifications 框架解析
2019独角兽企业重金招聘Python工程师标准>>> TL;DR iOS 10 中以前杂乱的和通知相关的 API 都被统一了,现在开发者可以使用独立的 UserNotificati ...
- iOS 10 的一个重要更新-开发 iMessage 的第三方插件
苹果官方的 Messages 在 iOS 10 推出了非常重大的更新,可能主要是想从其他 IM 巨头手里抢点市场份额回来,包括 Facebook Messenger, Wechat 和 Snapcha ...
- iOS 10 消息推送(UserNotifications)秘籍总结(二)
背景 上一篇博客iOS 10 消息推送(UserNotifications)秘籍总结(一)发布后被 简书编辑推荐至首页,这着实让我受宠若惊啊.可是好事不长,后面发生了让我伤心欲绝的事,我的女朋友不要我 ...
最新文章
- 华为实习日记——第二十二天
- canvas绘制圆形
- 8.0 C++远征:对象数组
- Containerpilot 配置文件reload
- linux bash中的引号:单双引号、反撇号
- ansa打开catia文件_关于CATIA文件格式的那些事儿
- 认识 lib 目录里的 .so 文件
- android 常用开发插件,Android Studio 开发利器【常用插件】
- C# 值类型 引用类型 作为参数传递区别
- Jedis之ShardedJedis虚拟节点一致性哈希分析
- 关于软考的一些事,你知道吗?
- Java语言学习指导与习题解答_Java语言程序设计(第3版)学习指导与习题解析
- excel中怎样制作下拉菜单
- Mysql之注入工具-yellowcong
- 学习笔记(1):FFmpeg打造Android万能音频播放器-实现变速变调功能(二)
- 2020-10-10
- Kubernetes 管理员认证(CKA)考试笔记(二)
- 物联网MQTT简单介绍
- biostar handbook(十一)|基因组变异的表示形式
- Spring关于AOP配置举例(XML配置文件方式)
热门文章
- ASP.NET——基础 12、Request
- Reddit热议被引最多的机器学习论文:上世纪LSTM称霸,何恺明今年被引1.8w居首...
- 地平线开源轻量级、有效可变组卷积的人脸识别网络VarGFaceNet
- 飞桨博士会第四期,中国深度学习技术俱乐部诚邀您加入
- Python 超简单一键美化你的文章
- const与指针变量
- 网络编程(一)基础知识
- 从零开始编写深度学习库(五)ConvolutionLayer CPU编写
- arcgis栅格邻域统计_地理工具学习--arcgis篇:单工具学习(14)
- tmp ubuntu 自动删除吗_tmp 目录文件被自动清理问题的调查