How to include NSPersistentContainer in AppDelegate
You should firstly import CoreData framework and then write this code in AppDelegate.swift:
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "Your Model File Name")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error {
fatalError("Unresolved error, \((error as NSError).userInfo)")
}
})
return container
}()
And then you should write this:
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext