Used this scenario as an example to be a bit more self explanatory. I have a struct which represents a character, and one of the structs attributes is another struct: Stats (where I used id to represent the name in a more simple way).
Besides that I have a view with a ForEach, where I iterate over some Characters and I need to be able to increase a specific stat.
The problem is: I'm trying to increase stat.points using a button, but I keep getting the message "Left side of mutating operator isn't mutable: 'product' is a 'let' constant".
struct Character: Identifiable {
var id: String
var name: String
var stats: [Stats]
}
struct Stats: Identifiable {
var id: String
var points: Int
}
ForEach(characters.stats) { stat in
HStack {
Text("\(stat.id)")
Button {
stat.points += 1
} label: {
Text("Increase")
}
}
}
How could I make this work?