From 2dc8182fe81a6778b5d00d184747316c6bc165cb Mon Sep 17 00:00:00 2001 From: Mingshen Sun Date: Tue, 18 Feb 2020 11:03:56 -0800 Subject: [PATCH] Update core data in main thread --- passKit/Models/PasswordStore.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/passKit/Models/PasswordStore.swift b/passKit/Models/PasswordStore.swift index 8f625c84..3eb49768 100644 --- a/passKit/Models/PasswordStore.swift +++ b/passKit/Models/PasswordStore.swift @@ -235,8 +235,8 @@ public class PasswordStore { try storeRepository.pull(storeRepository.currentBranch(), from: remote, withOptions: options, progress: progressBlock) Defaults.lastSyncedTime = Date() self.setAllSynced() - self.updatePasswordEntityCoreData() DispatchQueue.main.async { + self.updatePasswordEntityCoreData() NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil) } } @@ -566,7 +566,9 @@ public class PasswordStore { public func saveUpdatedContext() { do { - try context.save() + if context.hasChanges { + try context.save() + } } catch { fatalError("FailureToSaveContext".localize(error)) }