Learn Courses My Dashboard

Trying to get buttons to perform separate actions

Could someone help guide me? I have this code below that aligns my array of button names but I need each button to do its own action when pressed. As it is, whatever action I sign to the button - all the buttons do the same action. I would appreciate any help, Todd


struct PE: View {
  
    var spacing: CGFloat = 8
    var padding: CGFloat = 8
    var wordCount: Int = 75
    var alignmentIndex = 0

    var poswords: [String] {
        Array(p.posPE.prefix(wordCount))
    }
    var negwords: [String] {
        Array(p.negPE.prefix(wordCount))
    }

    let alignments: [HorizontalAlignment] = [.leading, .center, .trailing]

    var alignment: HorizontalAlignment {
      alignments[alignmentIndex]
    }
  
   @State private var note: String = ""
  
   
    var p:Pizza
    var body: some View {
        Text(p.name)
            .font(.largeTitle)
            .multilineTextAlignment(.leading)
            .padding(.vertical)
        
        
        // Positive findings
        SwiftUI.ScrollView {
          FlexibleView(
            data: poswords,
            spacing: spacing,
            alignment: alignment
          ){ topping in
             
          Button(topping) {}
          .padding()
          .clipShape(Capsule())
            .foregroundColor(Color.black)
            .background(Color.green.opacity(0.2))
            .font(.caption)
            .cornerRadius(13.0)
       }
                   }
                   .padding()