work around widgets ... not sure if they work
This commit is contained in:
@@ -26,7 +26,7 @@ struct AddMoodHeaderView: View {
|
||||
ForEach(Mood.allValues.reversed()) { mood in
|
||||
VStack {
|
||||
Button(action: {
|
||||
addItem(withMoodValue: mood.rawValue)
|
||||
addItem(withMood: mood)
|
||||
}, label: {
|
||||
mood.icon
|
||||
.resizable()
|
||||
@@ -47,21 +47,9 @@ struct AddMoodHeaderView: View {
|
||||
.padding()
|
||||
}
|
||||
|
||||
private func addItem(withMoodValue moodValue: Int) {
|
||||
private func addItem(withMood mood: Mood) {
|
||||
withAnimation {
|
||||
let newItem = MoodEntry(context: viewContext)
|
||||
newItem.timestamp = Date()
|
||||
newItem.moodValue = Int16(moodValue)
|
||||
newItem.forDate = Date()
|
||||
|
||||
do {
|
||||
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)")
|
||||
}
|
||||
PersistenceController.shared.add(mood: mood, forDate: Date())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user