fix crash where homeViewTwo view model wasnt being updated

This commit is contained in:
Trey t
2022-02-21 22:38:07 -06:00
parent 83060e8353
commit 769c6335d9
7 changed files with 50 additions and 18 deletions

View File

@@ -10,25 +10,12 @@ import Foundation
extension PersistenceController {
@discardableResult
public func update(entryDate: Date, withModd mood: Mood) -> Bool {
if let entry = PersistenceController.shared.getEntry(byDate: entryDate) {
viewContext.delete(entry)
}
do {
try PersistenceController.shared.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
}
add(mood: mood, forDate: entryDate, entryType: .listView)
do {
if let entry = PersistenceController.shared.getEntry(byDate: entryDate) {
viewContext.delete(entry)
}
try viewContext.save()
return true
} 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.
@@ -36,5 +23,21 @@ extension PersistenceController {
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
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
}
updateListeners()
return true
}
}