title: Change color of specific button inside ForEach loop SwiftUI
body: <p>I have a code that generates a list of buttons. What I want is when a button is pressed that button changes color. The problem I have is that the code does not let me do workout.isActive.toggle() as &quot;workout&quot; is apparently a &quot;let&quot; constant. How can I overcome this issue? I am still new to swift so any help would be appreciated :).</p>
  <pre><code>struct Workout: Identifiable {
      var id = UUID()
      var name: String
      var isActive: Bool
  
  }
  
      struct Workout_builder: View {
  
  var workouts = [
      Workout(name: &quot;Bench Press&quot;, isActive: false),
      Workout(name: &quot;Shoulder Press&quot;, isActive: false),
      Workout(name: &quot;Incline Press&quot;, isActive: false),
      Workout(name: &quot;Lateral Raises&quot;, isActive: false),
      Workout(name: &quot;Tricep Cable&quot;, isActive: false),]
          
  var body: some View {
  
      
      VStack {
          List {
              ForEach(workouts)  { workout in
                  Button(action: {
                      workout.isActive.toggle()
                  })
                  {
                      Text(workout.name)
                          .foregroundColor(.black)
                          .background(workout.isActive ? Color(.white) : Color(.blue))
                      }
                  }
              }
          }
      }
  }
  </code></pre>