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. jq中 offset()方法, scrollTop()方法以及scrollLeft()方法

    offset()方法是用来获取元素在当前视窗的相对偏移,其中返回的对象包含两个属性,即top和left,它只对可见元素有效. scrollTop()方法是用来获取元素的滚动条距离顶端的距离. scro ...

  2. Zuoye for guo

      A  B  C  D  E  A  -  3  6  10  13  B  -  -  5  9  12  C  -  -  -  10  13  D  -  -  -  -  9  E  -  ...

  3. sqlserver 索引

    什么是索引 拿汉语字典的目录页(索引)打比方:正如汉语字典中的汉字按页存放一样,SQL Server中的数据记录也是按页存放的,每页容量一般为4K .为了加快查找的速度,汉语字(词)典一般都有按拼音. ...

  4. tty驱动程序框架

    tty驱动程序框架 一.TTY概念解析 在Linux系统中,终端是一类字符型设备,它包括多种类型,通常使用tty来简称各种类型的终端设备. 1.1串口终端(/dev/ttyS*) 串口终端是使用计算机 ...

  5. 工作中遇到的问题--Hibernate注解添加在一方和多方的区别

    以Good和GoodStatus为例: 一.注解仅添加在一方: @Entity@Table(name = "GOOD")@Where(clause="enabled=1& ...

  6. Unity3d纹理压缩格式表

  7. Python正则表达式总结

    正则表达式也一直用,但是没系统的总结过,今天借这个时间梳理一下. Python中的正则表达式操作依靠re模块儿完成. 常用的方法: re.compile(pattern,flags=0) #返回一个编 ...

  8. caffe: compile error : undefined reference to `cv::imread(cv::String const&, int)' et al.

    when I compile caffe file : .build_debug/lib/libcaffe.so: undefined reference to `cv::imread(cv::Str ...

  9. Linux中/proc/[pid]/status详细说明

    [root@localhost ~]# cat /proc/self/status Name: cat State: R (running) SleepAVG: 88% Tgid: 5783 Pid: ...

  10. ABBYY FineReader的快速任务功能如何用

    在使用ABBYY FineReader Pro for Mac OCR文字识别软件处理文档时,经常会执行一系列相同的步骤,如扫描.识别.将已识别文本导出为特定格式或导出至特定应用程序.针对经常执行的任 ...