I have some monthly data that I need to calculate a specific value for before it gets displayed, using:
.onAppear{
ForEach(monthlyTilt) {item in
item.degrees = NewValue…
}
}
With a Struct/var combination of:
struct MonthlyTilt: Identifiable {
var id = UUID().uuidString
var month: String
var day: Int
var degrees: Double
}
var monthlyTilt = [
MonthlyTilt(month: "Jan", day: 15, degrees: 0.0),
MonthlyTilt(month: "Feb", day: 46, degrees: 0.0),
MonthlyTilt(month: "Mar", day: 74, degrees: 0.0),
MonthlyTilt(month: "Apr", day: 105, degrees: 0.0),
MonthlyTilt(month: "May", day: 135, degrees: 0.0),
MonthlyTilt(month: "Jun", day: 166, degrees: 0.0),
MonthlyTilt(month: "Jul", day: 196, degrees: 0.0),
MonthlyTilt(month: "Aug", day: 227, degrees: 0.0),
MonthlyTilt(month: "Sept", day: 258, degrees: 0.0),
MonthlyTilt(month: "Oct", day: 288, degrees: 0.0),
MonthlyTilt(month: "Nov", day: 319, degrees: 0.0),
MonthlyTilt(month: "Dec", day: 349, degrees: 0.0)
]
The error message reads: Cannot assign to property: 'item' is a 'let' constant. monthlyTilt is set as a var.
How can I update the degree value?
ForEachis used in aViewhierarchy. You may be looking formonthlyTilt.forEachdegreesafter you already created each struct, or do you just want to format the existing value ofdegreesdifferently for display purposes. These are two different approaches.