I want to open a view each time I click on the corresponding button, the issue is that the view is always called with the same index 0 and not the index where the button is created, here is my code:
private var symbols = ["plus.circle", "minus" , "multiply.circle", "divide.circle" ]
@State private var mathOp = ["+", "-", "*", "/"]
...
ForEach((0...symbols.count - 1), id: \.self) { index in
Button(action: {
self.isModal = true
}, label: {
Image(systemName: symbols[index % symbols.count])
.font(.system(size: 30))
.frame(width: 100, height: 50)
.foregroundColor(Color.black)
.cornerRadius(10)
}).sheet(isPresented: $isModal , content: {
MyView(Op: $mathOp[index % mathOp.count])
})
Do you have any idea?