Cover by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

15.1. Creating a Core Data Model with Xcode

Problem

You want to visually design the data model of your iOS application using Xcode.

Solution

Follow the instructions in this chapter’s Introduction to create a Core Data project. Then find the file with the extension of xcdatamodel in your application bundle in Xcode and click on it to open the visual data editor, as shown in Figure 15-4.

Visual data editor in Xcode

Figure 15-4. Visual data editor in Xcode

Discussion

Xcode’s visual data editor is a fantastic tool that allows programmers to design the data model of their applications with ease. There are two important definitions you need to learn before you can work with this tool:

Entity

Corresponds to a table in a database.

Attribute

Corresponds to a column in a table.

Entities will later become objects (managed objects) when we generate the code based on our object model. This is explained in Recipe 15.2. For now, in this recipe, we will concentrate on creating the data model in this tool.

In the editor, find the + button at the bottom. Press and hold your mouse button on this button and then select Add Entity from the menu that will appear, as shown in Figure 15-5.

Adding a new entity to our data model

Figure 15-5. Adding a new entity to our data model

Your new entity will be created and will be in a state where you can immediately rename it after creation. Change ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required