fix crash when updating an existing entry
code clean up
This commit is contained in:
@@ -10,34 +10,12 @@ import Foundation
|
||||
extension PersistenceController {
|
||||
@discardableResult
|
||||
public func update(entryDate: Date, withModd mood: Mood) -> Bool {
|
||||
do {
|
||||
if let entry = PersistenceController.shared.getEntry(byDate: entryDate) {
|
||||
viewContext.delete(entry)
|
||||
}
|
||||
|
||||
try viewContext.save()
|
||||
} catch {
|
||||
// Replace this implementation with code to handle the error appropriately.
|
||||
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
|
||||
let nsError = error as NSError
|
||||
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
|
||||
guard let existingEntry = getEntry(byDate: entryDate) else {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
|
||||
do {
|
||||
add(mood: mood, forDate: entryDate, entryType: .listView)
|
||||
try viewContext.save()
|
||||
} catch {
|
||||
// Replace this implementation with code to handle the error appropriately.
|
||||
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
|
||||
let nsError = error as NSError
|
||||
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
|
||||
return false
|
||||
}
|
||||
|
||||
runDataListeners()
|
||||
existingEntry.setValue(mood.rawValue, forKey: "moodValue")
|
||||
saveAndRunDataListerners()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user