clear core data when switch env

This commit is contained in:
Satindar Dhillon 2022-05-27 08:42:34 -07:00
parent 987336f438
commit 9b9191b6b1

View file

@ -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 }