solve core data conflict caused by updating password entity image

This commit is contained in:
Bob Sun 2017-02-16 13:24:41 +08:00
parent f1b14d794d
commit 83b9762122
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
2 changed files with 26 additions and 1 deletions

View file

@ -364,6 +364,29 @@ class PasswordStore {
}
}
func updateImage(passwordEntity: PasswordEntity, image: Data?) {
if image == nil {
return
}
let privateMOC = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
privateMOC.parent = context
privateMOC.perform {
passwordEntity.image = NSData(data: image!)
do {
try privateMOC.save()
self.context.performAndWait {
do {
try self.context.save()
} catch {
fatalError("Failure to save context: \(error)")
}
}
} catch {
fatalError("Failure to save context: \(error)")
}
}
}
func erase() {
Utils.removeFileIfExists(at: storeURL)
Utils.removeFileIfExists(at: tempStoreURL)