Understanding how saving and loading works
Let’s review what you have done so far. You have created Review
and RestaurantPhoto
entities using the data model editor, and you have created the corresponding model objects for them, named ReviewItem
and RestaurantPhotoItem
. You created the CoreDataManager
class to add and get Review
and RestaurantPhoto
instances from the persistent store. The CoreDataManager
class uses the restaurant identifier to associate reviews and restaurant photos with a specific restaurant, but where does it come from?
Open the Misc
folder in your project, and open the JSON
folder. If you click on any one of the JSON files inside, you’ll see that each restaurant has a unique numeric identifier. For example, the identifier for The Tap Trailhouse restaurant is 145237
, as shown in the screenshot below:
Figure 22.12: Editor area showing contents for Boston.json
When you save restaurant photos and reviews to the persistent store, you will...