How to initialise Core Data managedObjectContext using a model class?
How to initialise Core Data managedObjectContext using a model class? I am following Apple Documentation for core data stack, especially Initializing the Core Data Stack. Here is my code: import Foundation import CoreData class Cmodel: NSObject { var managedObjectContext: NSManagedObjectContext init(completionClosure: @escaping () -> ()) { //This resource is the same name as your xcdatamodeld contained in your project guard let modelURL = Bundle.main.url(forResource: "MySampleListView", withExtension:"momd") else { fatalError("Error loading model from bundle") } // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model. guard let mom = NSManagedObjectModel(contentsOf: modelURL) else { fatalError("Error initializing mom from: (modelURL)") } let psc = NSPersistentStoreCoordinator(managedObjectModel: mom) managedObjectContext =...