18.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 it to open the visual data editor, as shown in Figure 18-2.

Visual data editor in Xcode

Figure 18-2. 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 18.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. Click and hold on this button and then select Add Entity from the menu that will appear, as shown in Figure 18-3.

Your new entity will be created and will be in a state where you can immediately rename it after creation. Change the name of this entity to Person, as shown in Figure 18-4.

Adding a new entity to our data model

Figure 18-3. Adding ...

Get iOS 7 Programming Cookbook 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.