Please help. How do I get each button to perform a different action? With my code below every button does the same action when pressed.
var num:[String] = ["one", "two", "three", "four"]
struct test: View {
var body: some View {
VStack{
ForEach(num, id: \.self)
{index in
Button(index) {
print("Button pressed")
}
.padding()
.clipShape(Capsule())
.foregroundColor(Color.black)
.background(Color.green.opacity(0.2))
.font(.caption)
.cornerRadius(13.0)
}
}
}
}
struct test_Previews: PreviewProvider {
static var previews: some View {
test()
}
}
Any thoughts? Todd