Add a try catch when adding the persistant store back after switching between nodes.

This commit is contained in:
Garth Vander Houwen 2024-02-04 21:59:54 -08:00
parent 03e3bb2f46
commit ea4aa8a7ff

View file

@ -61,8 +61,13 @@ class PersistenceController {
do {
try persistentStoreCoordinator.destroyPersistentStore(at: url, ofType: NSSQLiteStoreType, options: nil)
try persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil)
print("💥 CoreData database truncated. All app data has been erased.")
do {
try persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil)
} catch let error {
print("💣 Failed to re-create CoreData database: " + error.localizedDescription)
}
} catch let error {
print("💣 Failed to destroy CoreData database, delete the app and re-install to clear data. Attempted to clear persistent store: " + error.localizedDescription)