title: How to change the var when selecting specific value on the Picker (SwiftUI)
body: <p>I need the <code>useRed</code> value to change to <code>true</code> when selecting <code>0%</code> in the UI picker (or <code>tipPercentage</code> becomes <code>4</code>).</p>
  
  <p>I tried the following but the warning "Modifying state during view update, this will cause undefined behavior" shows up and the <code>useRed</code> value remains <code>false</code>:</p>
  
  <pre><code>import SwiftUI
  
  struct ContentView: View {
  
  
      @State private var tipPercentage = 2
      @State private var useRed = false
  
      let tipPercentages = [10, 15, 20, 25, 0]
  
      var redCheck: Bool {
          if tipPercentage == 4 {
              useRed = true
          } else { useRed = false }
          return useRed
      }
  
  
      var body: some View {
  
          NavigationView {
              Form {
  
                  Section (header: Text("How much tips do you weant to leave?")){
                      Picker("Tip percentage", selection:
                      $tipPercentage) {
                          ForEach(0 ..&lt; tipPercentages.count) {
                              Text("\(self.tipPercentages[$0])%")
                          }
  
                          }
                        .pickerStyle(SegmentedPickerStyle())
                  }.foregroundColor(redCheck ? .red : .black)
  
              }
          }
      }
  </code></pre>