Creating a new project with Xcode 12 and 'Use Core Data' selected creates a Persistence.swift file instead of the previous AppDelegate.swift and SceneDelegate.swift files. I have used Persistence.swift to create the data base, add entries, view, and delete individual entries in my app project. Is it feasible to add AppDelegate.swift as well to my project to delete the entire data base? There are a number of methods described here Core Data: Quickest way to delete all instances of an entity.
For example, can this function be called from within AppDelegate.swift to delete all instances of an entity? How would that be done? By adding the function to the AppDelegate class? How would it be called?
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "Car")
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
do {
try myPersistentStoreCoordinator.execute(deleteRequest, with: myContext)
} catch let error as NSError {
// TODO: handle the error
}