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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.