I am a little confused as to how to delete all core data in swift. I have created a button with an IBAction linked. On the click of the button I have the follow
From iOS 9, there is the possibility of erasing persistent storage. For better maintenance – create NSPersistentStoreCoordinator extension with abstract function.
extension NSPersistentStoreCoordinator {
func destroyPersistentStore(type: String) -> NSPersistentStore? {
guard
let store = persistentStores.first(where: { $0.type == type }),
let storeURL = store.url
else {
return nil
}
try? destroyPersistentStore(at: storeURL, ofType: store.type, options: nil)
return store
}
}
Then destroying SQLite persistent storage looks pretty simple:
let coordinator = persistentContainer.persistentStoreCoordinator
let store = coordinator.destroyPersistentStore(type: NSSQLiteStoreType)