I have a fairly simple grid layout:
@State var gridSize = 3
@State var selected = 0
@State var aCount = 0
var body: some View {
Grid (horizontalSpacing: 0, verticalSpacing: 0) {
ForEach(0..<gridSize, id: \.self) { row in
GridRow{
ForEach(0..<gridSize, id: \.self) { col in
Rectangle()
.foregroundColor(.gray)
.overlay(Text("\(aCount)"))
.border(Color.black)
.bold()
}
}
}
}
}
}
This creates a grid of gridSize x gridsize grey rectangles, so 3x3 in this version
and in a class file I have a fairly simple function that increments an int passed to it by 1 and returns that new value:
let theCounter = theCount + 1
return theCounter
}
how do I use that function to increment aCount in the inner foreach loop? This does not seem like it should be impossible, and yet...
any help is appreciated
(Background: aCount is needed because I need to be able to have a click action in button 0,0 read the states of say, buttons 0,1 and 0,2 and have another function possibly change the state of all three depending on what is in 0,0, so aCount is used to help me manage an array of buttons.
(i have been told there's easier ways than an array of buttons to do this, but none of the explanations have worked for my level of inexperience, so an array of buttons is something I at least understand.