Database Reference
In-Depth Information
automatically decides if it's better to save the data to disk as a separate file or
leave it in the SQLite database.
Select the Employee entity and rename the
picture
attribute to
pictureThumbnail
. To do so, select the picture attribute in the diagram view and
then edit the name in the data model inspector.
You've updated the model so that now, it stores the original picture in a separate
entity and stores only a thumbnail version on the main Employee entity. The
smaller thumbnail pictures won't require as much RAM when the app fetches
Employee entities from Core Data. Once you've finished modifying the rest of the
project, you'll get a chance to test this out and verify that the app is using less RAM
than before.
You can link the two entities together with a relationship. That way, when the app
needs the higher-quality but larger picture, it can still retrieve it, via a relationship.
Select the
Employee
entity and click and hold the plus (+) button in the lower
right. This time, select
Add Relationship
. Name the relationship
picture
, set the
destination as
EmployeePicture
and finally, set the
Delete Rule
to
Cascade
.
Core Data relationships should always go both ways, so now add a corresponding
relationship. Select the
EmployeePicture
entity and add a new relationship. Name
the new relationship
employee
, set the
Destination
to
Employee
and finally, set
the
Inverse
to
picture
.
Your model should now look like this: