
16 CHAPTER 2: Core Data: What, Why, and How
there are three menu items: Add Attribute, Add Relationship, and Add Fetched Property. These are
only active when an entity is selected in the Top-Level Components pane.
If you switch the Detail editor to graph style, you’ll see a large grid with a single rounded square
in the center. This rounded square represents the entity in the Top-Level Components pane. The
template you used for this project creates a single entity, Event. Selecting Event in the Top Level
Components pane is the same as selecting the rounded rectangle in the graph view.
Try it. Click outside the entity in the Detail editor grid to deselect it, and then click the Event line in
the Top-Level Components pane. The entity in the graph view will also be selected. The Top Level
Components pane and the graph view show two different views of the same entity list.
When unselected, the title bar and lines of the Event entity square should be pink. If you select the
Event entity in the Top-Level Components pane, the Event entity in the Detail editor should change
color to a blue, indicating it’s selected. Now click anywhere on the Detail editor grid, outside the
Event rounded square. The Event entity should be deselected in the Top Level Components pane
and should change color in the Detail editor. If you click on the Event entity in the Detail editor, it will
be selected again. When selected, the Event entity should have a resize handle (or dot) on the left
and right sides, allowing you to resize its width.
You are currently given the Event entity. It has a single attribute, named timeStamp, and no
relationships. The Event entity was created as part of this template. As you design your own data
models, you’ll most likely delete the Event entity and create your own entities from scratch. A
moment ago, you ran your Core Data sample application in the simulator. When you pressed
the + icon, a new instance of Event was created. Entities, which we’ll look at more closely in a few
pages, replace the Objective-C data model class you would otherwise use to hold your data. We’ll
get back to the model editor in just a minute to see how it works. For now, just remember that the
persistent store is where Core Data stores its data, and the data model defines the form of that data.
Also remember that every persistent store has one, and only one, data model.
The inspector provides greater detail for the item(s) selected in the model editor. Since each item
could have a different view in the inspector, we’ll discuss the details as we discuss the components
and their properties. That being said, let’s discuss the three top-level components: entities, fetch
requests, and configurations.
Entities
An entity can be thought as the Core Data analogue to an Objective-C class declaration. In fact,
when using an entity in your application, you essentially treat it like an Objective-C class with some
Core Data-specific implementation. You use the model editor to define the properties that define
your entity. Each entity is given a name (in this case, Event), which must begin with a capital letter.
When you ran CoreDataApp earlier, every time you pressed the Add (+) button, a new instance of
Event was instantiated and stored in the application’s persistent store.
Make sure the Utility pane is exposed, and select the Event entity. Now look at the inspector in the
Utility pane (make sure the enspector is showing by selecting the Inspector button in the Inspector
selector bar). Note that the Inspector pane now allows you to edit or change aspects of the entity
(Figure 2-10). We’ll get to the details of the inspector later.
www.it-ebooks.info