Building the Core Data Stack

The Core Data stack consists of the classes that interface with your entities as well as the model file that describes the entities to save and load instances to a store (such as the filesystem). You will learn about each component in the stack and what role it plays in Core Data.

Create a new Swift file and name it CoreDataStack. Open this file and declare the CoreDataStack class along with a required initializer that accepts the name of the model file. Do not forget to import the Core Data framework.

import Foundation
import CoreData

class CoreDataStack {

    let managedObjectModelName: String

    required init(modelName: String) {
        managedObjectModelName = modelName
    }

}

NSManagedObjectModel

You worked ...

Get iOS Programming: The Big Nerd Ranch Guide 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.