Chapter 5. Core Data

Every application needs to store information, whether during the course of a single session or permanently. To aid in the difficult task of managing and searching stored data, Apple has developed a whole framework called Core Data, which you might already be familiar with. In iOS 11 SDK, Core Data, especially in Swift, has been changed a little bit, so in this chapter we will have a look at these changes as well as some basics of accessing Core Data.

Before we go further, ensure that you have added the necessary Core Data code to your application. When you create your project file, make sure to tell Xcode to import Core Data into your application. You do this when you enter your product’s name in Xcode’s new project dialog, as shown in Figure 5-1. Core Data is one of the three features you can choose at the bottom of the dialog.

Figure 5-1. At the bottom of this dialog, you can ask Xcode to add Core Data to your project

5.1 Designing Your Database Scheme

Problem

You want to begin storing data in Core Data.

Solution

The idea behind Core Data is that your data is organized and stored in the database through what are known as schemes.  Schemes tell Core Data how your data is structured, and can be designed through a visual editor that’s part of Xcode.

Note

Ensure that you have added Core Data to your project by following the instructions given in this chapter’s ...

Get iOS 11 Swift Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.