Lesson 26

Introduction to Core Data

The Core Data framework provides solutions to tasks commonly associated with managing the lifecycle of objects in your application, including object serialization. Prior to Core Data, programmers relied on SQLite to store their application data; Core Data can be viewed as an object-oriented wrapper around a SQLite database. It provides you with a convenient mechanism to create, update, and delete entities in the database without having to write a single line of SQL. In this lesson, you learn to use Core Data to implement simple object persistence in your applications.

Basic Concepts

Core Data is based on the Model-View-Controller pattern and essentially fits in at the model stage. It forces you to think of your applications data in terms of objects. Core Data introduces quite a few new concepts and terminology. These are discussed briefly in this section. Figure 26.1 provides an overview of the key classes introduced by Core Data.

Diagram of Key Classes controlled by core Data, classified into Managed Object Context, Persistent Store Coordinator, and Managed Object Model.

Figure 26.1

Managed Object

A managed object is a representation of the object that you want to save to the data store. This is conceptually similar to a record in a relational database table and typically contains fields that correspond to properties in the object you want to save. The lifecycle of managed objects is managed by Core Data; you should not hold strong references in your code to managed objects. ...

Get Swift iOS 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.