I am currently working on a project for the Swift Student Challenge. One part of the app is for visualizing goals with a chart created using Swift Charts. In the app, you log your progress for the goal and then it should show up in the chart. My issue is that the data is not showing after it has been logged. Here are some code snippets:
Code For Chart View
Chart {
let currentDate = Date.now
BarMark (
x: .value("Day", "Today"),
y: .value("Score", goalItem.getLogItemByDate(date: currentDate).score)
)
}
.frame(maxHeight: 225)
.padding()
GoalItem
Data Object
public class GoalItem: Identifiable {
public var id: String
var name: String
var description: String
var logItems: [String: GoalLogItem]
init(name: String, description: String) {
self.id = UUID().uuidString
self.name = name
self.description = description
self.logItems = [:]
}
func log(date: Date, score: Double, notes: String) {
self.logItems[dateToDateString(date: date)] = GoalLogItem(date: date, score: score, notes: notes)
}
func getLogItemByDate(date: Date) -> GoalLogItem {
let logItem = self.logItems[dateToDateString(date: date)]
if logItem != nil {
return logItem!
} else {
return GoalLogItem(isPlaceholder: true)
}
}
}
After logging something using the GoalItem.log method, why does it not show up in the chart? Are the variables not updated? If so, how would I get the variables to update?
Thanks