I'm trying to change the attribute of points by adding 1 every time the button is pressed, however, it does not change. How could I accomplish this?
class Person{
var name = ""
var points = 0
}
var Greg = Person()
var Jeo = Person()
var Humio = Person()
init(Greg: Person = Person(), Jeo: Person = Person(), Humio: Person = Person()) {
self.Greg = Greg
self.Jeo = Jeo
self.Humio = Humio
Greg.name = "Greg"
Jeo.name = "Jeo"
Humio.name = "Humio"
}
var body: some View {
var nombres:[Person] = [Greg, Jeo, Humio]
VStack {
ForEach(nombres, id: \.name){
names in
ZStack{
Rectangle()
.frame(width: 200, height: 200)
VStack{
Text("\(names.points)")
.foregroundColor(Color.white)
Button(action: {
names.points += 1
}, label: {
Text(names.name)
})
}
}
}
}
.padding()
}
}