diff --git a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift index 6878a40dc..5c458ea3c 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift @@ -59,9 +59,8 @@ public final class DataService: ObservableObject { await networker.hasConnectionAndValidToken() } - private func resetCoreData() { - let storeContainer = - persistentContainer.persistentStoreCoordinator + private func clearCoreData() { + let storeContainer = persistentContainer.persistentStoreCoordinator do { for store in storeContainer.persistentStores { @@ -71,18 +70,23 @@ public final class DataService: ObservableObject { options: nil ) } - persistentContainer = PersistentContainer.make() - persistentContainer.loadPersistentStores { _, error in - if let error = error { - fatalError("Core Data store failed to load with error: \(error)") - } - } - backgroundContext = persistentContainer.newBackgroundContext() } catch { - logger.debug("Failed to reset core data stores") + logger.debug("Failed to clear core data stores") } } + private func resetCoreData() { + clearCoreData() + + persistentContainer = PersistentContainer.make() + persistentContainer.loadPersistentStores { _, error in + if let error = error { + fatalError("Core Data store failed to load with error: \(error)") + } + } + backgroundContext = persistentContainer.newBackgroundContext() + } + private func isFirstTimeRunningNewAppVersion() -> Bool { let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") guard let appVersion = appVersion as? String else { return false }