Adding Core Data to an existing application

When you create a new project in Xcode, Xcode asks whether you want to add Core Data to your application. If you check this checkbox, Xcode will automatically generate some boilerplate code that sets up the Core Data stack. For practicing purposes, MustC was set up without Core Data so you'll have to add this to the project yourself. Start by opening AppDelegate.swift and add the following import statement:

import CoreData 

Next, add the following lazy variable to the implementation of AppDelegate:

private lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentContainer(name: "MustC") container.loadPersistentStores(completionHandler: { (storeDescription, error) in if ...

Get Mastering iOS 12 Programming - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.