What is Core Data?

If you want to build anything beyond the most simplistic apps for iOS, you’ll need a way to persist data. Luckily, Apple provides the Core Data framework, a persistence layer that efficiently handles the coordination of saving/updating/deleting data, as well as maintaining data integrity.

With Core Data, you define the schema you want your data to conform to, and afterwards create objects from that schema to perform CRUD operations on. You don’t have to worry about what’s going on at the actual database level, as this is all abstracted away.

It’s worth noting that Core Data is not itself a database. By default, it sits on top of SQLite3, a lightweight database baked into iOS. However, it can be configured to persist data to a document file or, in the case of the StackMob SDK, a URL service that persists the data elsewhere.

Why Should I Learn Core Data?

Before Core Data, developers had to work directly with SQLite3 to save their data. This provided many headaches; you had to write verbose SQL commands and handle the logic for CRUD operations. You were also responsible for insuring the data you saved matched your schema. By the end of it all, you had in essence written your own persistence layer! Core Data handles all the heavy lifting for you. As you persist your data all logic is managed under the hood with optimal performance in mind.

Core Data has a little bit of a learning curve, which can dissuade developers who want to dive straight into building to use it. However, taking the time to gain an understanding of the Core Data fundamentals will pay large dividends in the long run, as it is a powerful tool that will enable you to build robust and data-driven apps.

Lets Get Started

The NSManagedObjectModel is where you define your schema for Core Data. In your model, you define theEntities, or classes of data in your schema. Within your Entities, you set their Attributes, which are the details of your data. Finally, you can link Entities together through Relationships.

NSManagedObjectContext & NSPersistentStoreCoordinator

The NSManagedObjectModel is only ⅓ of the Core Data picture. Let’s introduce the NSManagedObjectContext. You can think of NSManagedObjectContext as a “scratch pad” where all the changes happen. Here you create, read, update and delete objects from your database. None of the changes you make are actually persisted until you call the “save” method on your managed object context instance.

So when a call to save is made, what happens next? Sitting between the managed object context and the database is the NSPersistentStoreCoordinator. The coordinator acts as an interface to the database where your data is being persisted. The persistent store coordinator grabs any objects that will be saved from the managed object context and verifies that names and types are consistent with the managed object model. It then sends the objects on their way to be persisted to the database.

from:https://blog.stackmob.com/2012/11/iphone-database-tutorial-part-1-learning-core-data/

Learning Core Data 1的更多相关文章

  1. 《驾驭Core Data》 第一章 Core Data概述

    <驾驭Core Data>系列教程综合了<Core Data for iOS>,<Learning Core Data for iOS>,<Core Data ...

  2. 使用Core Data应避免的十个错误

    原文:Avoiding Ten Big Mistakes iOS Developers Make with Core Data   http://www.cocoachina.com/applenew ...

  3. iOS开发过程中使用Core Data应避免的十个错误

    原文出处: informit   译文出处:cocoachina Core Data是苹果针对Mac和iOS平台开发的一个框架,主要用来储存数据.对很多开发者来说,Core Data比较容易入手,但很 ...

  4. iOS之Core Data及其线程安全

    一.简介 Core Data是iOS5之后才出现的一个框架,它提供了对象-关系映射(ORM)的功能,即能够将OC对象转化成数据,保存在SQLite数据库文件中,也能够将保存在数据库中的数据还原成OC对 ...

  5. Core Data的一些常见用法

    一.简介 Core Data是一个纯粹的面向对象框架,其本质就是一个ORM(对象关系映射:Object Relational Mapping),能以面向对象的方式操作SQLite数据库.在实际开发中绝 ...

  6. Learning From Data 第一章总结

    之前上了台大的机器学习基石课程,里面用的教材是<Learning from data>,最近看了看觉得不错,打算深入看下去,内容上和台大的课程差不太多,但是有些点讲的更深入,想了解课程里面 ...

  7. Core Data 使用映射模型

    Core Data 使用映射模型 如果新版本的模型存在较复杂的更改,可以创建一个映射模型,通过该模型指定源模型如何映射到目标模型. 创建映射模型,新建File,  Core Data 选择Mappin ...

  8. SELF, self in CORE DATA

    Predicate SELF Represents the object being evaluated. CORE DATA Retrieving Specific Objects If your ...

  9. Core Data浅谈初级入门

    Core Data是iOS5之后才出现的一个框架,它提供了对象-关系映射(ORM)的功能,即能够将OC对象转化成数据,保存在SQLite数据库文件中,也能够将保存在数据库中的数据还原成OC对象.在此数 ...

随机推荐

  1. hihoCoder #1078 : 线段树的区间修改

    题目大意及分析: 线段树成段更新裸题. 代码如下: # include<iostream> # include<cstdio> # include<cstring> ...

  2. Foundation框架 - 快速创建跨平台的网站页面原型

    API参考:http://foundation.zurb.com/docs/ 作为网页设计和开发人员,我们面临着以下几个严峻的问题: 每天,人们用来上网的设备种类和数量都在不断上升. 为每种设备设计开 ...

  3. T4 Templates

    T4 Templates and the Entity Framework https://msdn.microsoft.com/en-us/data/gg558520.aspx EF Designe ...

  4. 轮播图切换 纯html+js+css

    如图所示. 该图片切换特效实现很简单,而且兼容性很好. html页面如下 复制代码代码如下: <div class="wrapper"> <div id=&quo ...

  5. eclipse中新建maven项目-转

    http://huxiaoheihei.iteye.com/blog/1766986 博客分类: maven maven  maven是个项目管理工具,集各种功能于一身,下面介绍maven web项目 ...

  6. 004. 线程间操作无效: 从不是创建控件“textBox1”的线程访问它

    最简单的方法(不推荐): 在窗体构造函数中写Control.CheckForIllegalCrossThreadCalls =false; 为什么不推荐上面的方法: 为避免空间造成死锁, .net f ...

  7. HTML相对路径 当前目录、上级目录、根目录、下级目录表示法

    文件引用时经常需要用到相对目录.如(js,css,图片等) "./"  ---------       源代码所在的当前目录(可省略) "../"  ----- ...

  8. wikioi 1474 十进制转m进制

    /*===================================== 1474 十进制转m进制 题目描述 Description 将十进制数n转换成m进制数 m<=16 n<=1 ...

  9. WCF Client is Open Source

    WCF Client is Open Source Wednesday, May 20, 2015 Announcement New Project WCF We’re excited to anno ...

  10. 【转载】写runat="server"有什么用

    aspx运行时会被编译,其中没有runat="server"属性的html标签会被直接写入response,有runat="server"属性的html标签会转 ...