Core Data编程指南 1-1:什么是Core Data

Core Data是Cocoa中针对数据层的一个软件架构,用于管理应用程序数据层对象。它提供了一系列通用的数据处理方法,包括数据对象生命周期管理、可视化以及持久存储等。

Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence.

因为提供了以下这些内置功能,Core Data减轻了50-70%的数据层编程工作量:

Core Data typically decreases by 50 to 70 percent the amount of code you write to support the model layer. This is primarily due to the following built-in features that you do not have to implement, test, or optimize:

  • 记录修改历史,支持类似文本编辑中的undo和redo功能。
  • Change tracking and built-in management of undo and redo beyond basic text editing.
  • 自动完成数据输入,在数据修改过程中修改相关联数据,扩展相关关系,保证数据完整性
  • Maintenance of change propagation, including maintaining the consistency of relationships among objects.
  • 带有预测性地按需载入数据,通过共享调度(copy-on-write),减少数据写入时的搬运开销。
  • Lazy loading of objects, partially materialized futures (faulting), and copy-on-write data sharing to reduce overhead.
  • 可进行自动数据验证。Core Data中的数据对象提供了可扩展的数据验证接口,保证输入的新数据是可接受的,并且不和其他相关数据冲突。
  • Automatic validation of property values. Managed objects extend the standard key-value coding validation methods to ensure that individual values lie within acceptable ranges, so that combinations of values make sense.
  • 高效的数据结构迁移工具,能简化数据结构迁移工作。
  • Schema migration tools that simplify schema changes and allow you to perform efficient in-place schema migration.
  • 能灵活地集成到控制层中,实现数据和用户界面同步。
  • Optional integration with the application’s controller layer to support user interface synchronization.
  • 在内存和用户界面中方便地组织,过滤数据。
  • Grouping, filtering, and organizing data in memory and in the user interface.
  • 支持将数据存储在外部数据库中。
  • Automatic support for storing objects in external data repositories.
  • 支持精确查询。NSPredicate对象支持一系列丰富的、类似SQL语言的查询方法来获取数据。
  • Sophisticated query compilation. Instead of writing SQL, you can create complex queries by associating an NSPredicate object with a fetch request.
  • 支持版本管理和并发写入。
  • Version tracking and optimistic locking to support automatic multiwriter conflict resolution.
  • 方便地和macOS,iOS工具链整合。
  • Effective integration with the macOS and iOS tool chains.

备注 NOTE

本文档使用一个结构复杂但易于理解的雇员数据库来做示例。但是Core Data架构并不仅仅适用于数据库样式的应用程序,也并不局限于client-server结构。这是一个基础的数据处理架构,类似Sketch之于矢量图形处理应用程序,或者Keynote之于演示文稿应用程序。

This document uses an employees database-style example for expediency and clarity. It represents a rich but easily understood problem domain. However, the Core Data framework is not restricted to database-style applications, nor is there an expectation of client-server behavior. The framework is equally as useful as the basis of a vector graphics application such as Sketch or a presentation application such as Keynote.

你可能感兴趣的:(Core Data编程指南 1-1:什么是Core Data)