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. 学习使用:before和:after伪元素

    http://www.w3cplus.com/css3/learning-to-use-the-before-and-after-pseudo-elements-in-css.html

  2. 工作中遇到的问题--使用DTO减少数据字段

    Location中包含如下字段以及AMfgObject中关于创建信息的字段,然而有时使用并不需要传输那么多数据,则对其中字段进行过滤. @Entity@Table(name = "LOCAT ...

  3. PHP 安装 eaccelerator

    安装开发工具包: yum groupinstall -y "Development Tools" 查看本机php版本: rpm -qi php 下载rpm包: wget http: ...

  4. Java——集合框架 工具

     /* * Arrays工具类的使用 */ public class ArraysTest { public static void main(String[] args) { // TODO A ...

  5. 黑马程序员——JAVA基础之构造函数,构造代码块

    ------- android培训.java培训.期待与您交流! ---------- 构造函数特点: 1.  函数名与类名相同 2.  不用定义返回值类型 3.  不可以写return语句 构造函数 ...

  6. Linux下tmpfs介绍及使用

    tmpfs介绍 tmpfs是一种虚拟内存文件系统,而不是块设备.是基于内存的文件系统,创建时不需要使用mkfs等初始化它最大的特点就是它的存储空间在VM(virtual memory),VM是由lin ...

  7. 主成分分析(PCA)

    主成分分析(principal component analysis)是一种常见的数据降维方法,其目的是在"信息"损失较小的前提下,将高维的数据转换到低维,从而减小计算量.PCA的 ...

  8. Is it possible to configure PostgreSQL to automatically close idle connections?

    1.use pgbouncer As new connections/transactions/statements arrive, the pool will increase in size up ...

  9. mybatis 批量插入和where条件使用

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-/ ...

  10. Linux静态库和共享库

    1.什么是静态库静态库类似windows中的静态lib 关于windows中的静态lib,可参考 Windows动态链接库DLL 特点:包含函数代码声明和实现,链接后所有代码都嵌入到宿主程序中. 只在 ...