Core Data Tutorial for iOS——Introduction

来源:互联网 发布:王者荣耀无法连接网络 编辑:程序博客网 时间:2024/04/30 05:38

Introduction导言

Core Data is a schema-driven object graph management and persistence framework. Fundamentally, Core Data helps you to save model objects (in the sense of the model-view-controller design pattern) to a file and get them back again. This is similar to archiving (see Archives and Serializations Programming Guide), but Core Data offers much more than that. Amongst other things, it:

Core Data是一个模型驱动的对象关系图管理和持久存储框架。从根本上说,Core Data有助于你将模型对象(模型 - 视图 - 控制器设计模式意义上的)保存到一个文件中,以及将他们取回来。这类似于归档(参看归档和序列化编程指南),但Core Data提供的更多。除此以外,它还提供:

  • Provides an infrastructure for managing all the changes to your model objects. This gives you automatic support for undo and redo, and for maintaining reciprocal relationships between objects.

  • 提供一个基础架构,用于管理你的模型对象的所有更改。这使您的app自动支持撤消和重做,并能维护对象之间的相互关系。

  • Allows you to keep just a subset of your model objects in memory at any given time. This is especially important on iOS where conserving memory is critical.

  • 允许在任何时刻只在内存中保存一份模型对象们的子集。这对于IOS这种节约内存很关键的系统尤其重要。
  • Uses a schema to describe the model objects. You define the principal features of your model classes—including the relationships between them—in a GUI-based editor. This provides a wealth of basic functionality “for free,” including setting of default values and attribute value validation.

  • 用一个模型来描述模型对象。在一个基于GUI的编辑器中,你可以定义模型泪的主要特性——包括它们之间的关系。这提供了丰富的免费功能,包括默认值的设置和属性值验证。
  • Allows you to maintain disjoint sets of edits of your objects. This is useful if you want to, for example, allow the user to make edits in one view that may be discarded without affecting data displayed in another view.

  • 允许你保持编辑对象的不相交集合。例如。如果你想让用户在一个视图里实施编辑操作,而在另一个视图中为了不影响数据的展示又要舍弃第一个视图中的更改,这个功能就会非常有用了。
  • Has an infrastructure for data store versioning and migration. This lets you easily upgrade an old version of the user’s file to the current version.

  • 对于数据存储的版本和迁移有基础支持。这可以令你轻松地将用户文件从旧版本升级为新版本。

Core Data is available on iOS 3.0 and later. 

Core Data只在ios3.0及之后的版本中提供。

You should read this document to learn how to use Core Data on iOS, including:

在IOS中,你应该阅读本文档来学习如何使用Core Data。包括:

  • The fundamental design patterns and techniques that underlie Core Data

  • 基本的设计模式和技术,这些是 Core Data的基础

  • The basics of using the Xcode data modeling tool

  • 使用Xcode数据建模工具的基础
  • How to create, update, and delete objects managed by Core Data, and how to commit changes to a data store
  • 如何新建、更新和删除由Core Data管理着的对象,以及如何提交改变到数据存储中

Important: Core Data is not an entry-level technology. Before starting to use Core Data, you must understand the basics of iOS application development, including:

重要提示:Core Data不是一个入门级的技术。在开始使用Core Data之前,你必须了解iOS应用程序开发的基础知识,包括:

  • How to use Xcode and Interface Builder

  • 如何使用Xcode和Interface Builder

  • Fundamental design patterns such as model-view-controller and delegation

  • 基本的设计模式,如模型 - 视图 - 控制器和代理

  • How to use view controllers, navigation controllers, and table views

  • 如何使用视图控制器,导航控制器和表视图

None of these tools and techniques are explained in this tutorial, so that the content can focus on Core Data itself.为了让内容关注Core Data本身,本教程不会解释说明这些工具和技术。

Documents you should read to gain adequate experience include:

你应该阅读下列文档,以获得足够的经验:

  • Your First iOS App

  • Xcode Workspace Guide

  • Cocoa Fundamentals Guide

  • View Controller Programming Guide for iOS

  • Table View Programming Guide for iOS

Organization of This Document

This tutorial comprises the following chapters:本教程包括以下章节:

  • “Starting Out”

  • “The Table View Controller”

  • “Managed Object and Model”

  • “Adding Events”

  • “Fetching Events”

  • “Deleting Events”

  • “Next Steps”

The source code for the tutorial is provided in the Locations sample code.

本教程的源代码由Locations示例代码提供。