I have checked that because I am using an iOS playground I can't use the Observable macro as it seems to be unavailable in an iOS playground. Here is my full code for the SwiftUI view if this helps at all (P.S. I tried adding @State to goalItem but that didn't seem to do anything):
import Charts
enum ChartTimeFrame: String, CaseIterable, Identifiable {
case week, month, sixMonth, year, all
var id: Self { self }
}
struct GoalDetailView: View {
@State var goalItem: GoalItem
@State private var pickerTimeFrame: ChartTimeFrame = ChartTimeFrame.week
@State private var showLogSheet: Bool = false
@State var logScore: Double = 6.0
@State var logNotes: String = ""
@State var logDate: Date = Date.now
@Environment(\.dismiss) var dismiss
var body: some View {
VStack {
Picker("Timeframe", selection: $pickerTimeFrame) {
Text("W").tag(ChartTimeFrame.week)
Text("M").tag(ChartTimeFrame.month)
Text("6M").tag(ChartTimeFrame.sixMonth)
Text("Y").tag(ChartTimeFrame.year)
Text("ALL").tag(ChartTimeFrame.all)
}
.pickerStyle(.segmented)
.padding()
Chart {
let currentDate = Date.now
BarMark (
x: .value("Day", "Today"),
y: .value("Score", goalItem.getLogItemByDate(date: currentDate).score)
)
}
.frame(maxHeight: 225)
.padding()
Spacer()
List {
NavigationLink(destination: GoalDataList(goalItem: goalItem)) {
Text("Show All Data")
}
.navigationTitle(goalItem.name)
.toolbar {
Button("Log") {
showLogSheet.toggle()
}
.sheet(isPresented: $showLogSheet) {
// goal log sheet code
GoalLogSheet(goalItem: goalItem)
}
}
}
.scrollDisabled(true)
}
}
}
Thanks again