From ea4aa8a7ffbc18c9f391781a5a261bd2579370fa Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 4 Feb 2024 21:59:54 -0800 Subject: [PATCH] Add a try catch when adding the persistant store back after switching between nodes. --- Meshtastic/Persistence/Persistence.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Meshtastic/Persistence/Persistence.swift b/Meshtastic/Persistence/Persistence.swift index 1c768ccf..2bb447f7 100644 --- a/Meshtastic/Persistence/Persistence.swift +++ b/Meshtastic/Persistence/Persistence.swift @@ -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)