Database Reference
In-Depth Information
You may be wondering why the model editor uses the term “Entity.” Weren't you
simply defining a new class? As you'll see shortly, Core Data comes with its own
vocabulary. Here's a quick rundown of some of the terms you'll commonly
encounter:
An entity is a class definition in Core Data. The classic example is an Employee or
a Company . In a relational database, an entity corresponds to a table.
An attribute is a piece of information attached to a particular entity. For
example, an Employee entity could have attributes for the employee's name,
position and salary. In a database, an attribute corresponds to a particular field in
a table.
A relationship is a link between multiple entities. In Core Data, relationships
between two entities are called to-one relationships , while those between one
and many entities are called to-many relationships . For example, a Manager can
have a to-many relationship with a set of employees, whereas an individual
Employee will have a to-one relationship with his manager.
Note: As you've probably noticed, entities sound a lot like a classes. Likewise,
attributes/relationships sound a lot like properties. What's the difference? You
can think of a Core Data entity as a class “definition” and the managed object
as an instance of that class.
Now that you know what an attribute is, go back to the model editor and add an
attribute to Person . Select Person on the left-hand side and click the plus sign (+)
under Attributes .
Set the new attribute's name to, well, name and change its type to String :
In Core Data, an attribute can be of one of several data types. You will learn about
these in the next few chapters.
Search WWH ::




Custom Search