title: SwiftUI Picker VALUE
body: <p>I've been trying to program something with swiftui recently,
  it's difficult, how can I transfer the value of the picker into the
  text field, I'm desperate!</p>
  <p>and why can I not work with the value $ khValue directly as in the text field?</p>
  <p>I've already spent hours searching the internet… I haven't found anything yet, swiftUI is completely different from swift</p>
  <pre><code>import SwiftUI
  
  struct KH_aus_Co2: View {
      @State private var kh_Picker : String = &quot;&quot;
      @State private var ph_Picker: String = &quot;&quot;
      
      
      
      var kh_vol = [Int](0..&lt;21)
      var ph_vol = [Int](0..&lt;10)
      
      init(){
          UITableView.appearance().backgroundColor = .clear
      }
      
      @State private var khWert: String = &quot;&quot;
      @State private var phWert: String = &quot;&quot;
      @State private var phco2Wert: String = &quot;&quot;
      
      
      
      var calculation: String {
          
          guard khWert.isEmpty == false, phWert.isEmpty == false else { return &quot;&quot; }
          
          
          guard let kh = Double(khWert), let ph  = Double(phWert) else { return &quot;Error&quot; }
          
          let product = kh/2.8 * pow(10,7.90-ph)
          
          
          return String(format: &quot;%.2f&quot;, product)
      }
      
      
      
      var body: some View {
          
          VStack() {
              Text(&quot;Co2 = \(calculation) mg/ltr&quot;)
                  
                  .font(.largeTitle)
                  .multilineTextAlignment(.center)
                  .foregroundColor(Color.green)
                  .frame(width: 300, height: 60, alignment: .center)
                  .border(Color.green)
                  .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
              
              
              
              HStack {
                  
                  
                  TextField(&quot;KH Wert&quot;, text: $khWert)
                      .border(Color.green)
                      .frame(width: 120, height: 70, alignment: .center)
                      .textFieldStyle(RoundedBorderTextFieldStyle())
                      //                            .textContentType(.oneTimeCode)
                      .keyboardType(.numberPad)
                  
                  TextField(&quot;PH Wert&quot;, text: $phWert)
                      .border(Color.green)
                      .frame(width: 120, height: 70, alignment: .center)
                      .textFieldStyle(RoundedBorderTextFieldStyle())
                      //                            .textContentType(.oneTimeCode)
                      .keyboardType(.numberPad)
                  
              }
              
              GeometryReader { geometry in
                  HStack {
                      
                      Picker(selection: self.$kh_Picker, label: Text(&quot;&quot;)) {
                          ForEach(0 ..&lt; self.kh_vol.count) { index in
                              Text(&quot;\(self.kh_vol[index])&quot;).tag(index)
                              //
                          }
                          
                      }
                      .frame(width: geometry.size.width/3, height: 100, alignment: .center) .clipped()
                      
                      Picker(selection: self.$ph_Picker, label: Text(&quot;&quot;)) {
                          ForEach(0 ..&lt; self.ph_vol.count) { index in
                              Text(&quot;\(self.ph_vol[index])&quot;).tag(index)
                          }
                          
                      }
                      .frame(width: geometry.size.width/3, height: 100, alignment: .center) .clipped()
                      
                      
                  }
              }
              
          }
              
              
          .navigationBarTitle(Text(&quot;Co2 aus KH &amp; PH&quot;))
          .font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/)
          
          
      }
      
      
      
  }
  
  struct KH_aus_Co2_Previews: PreviewProvider {
      static var previews: some View {
          Co2_aus_KH()
          
      }
  }
  </code></pre>
  <p>big thanks for your help</p>
  <p>Jürgen....................................</p>