title: List with value and title from array in SwiftUI
body: <p>I want to create a list that each item have a title and a value. The value in the array have to be mutable to that the user type a new value it changes the value in the array.</p>
  <p>Currently I tried fake this by implementing new row instead of using foreach.</p>
  <p>There is a Model called <code>Affiliate</code> and he have few properties. Each one have a <code>Double</code> as value. Some of them are just for presenting the values after dividing calculation.</p>
  <p>I wonder how can I can use array and foreach instead of create each var independently.</p>
  <p>My shot:</p>
  <pre><code>struct Affiliate: Codable, Identifiable{
      
      var id = UUID().uuidString
      
      var presentOfGoal: Double{
          return actualSales / affiliateGoal
      }
      var hourlyDeal: Double {
          return salesNumber / salePH
      }
      var hourlyOutput: Double{
          return sumSales / workHours
      }
      var averageDeal: Double{
          return sumSales / salesNumber
      }
      var averageIPT: Double {
          return productsNum / salesNumber
      }
      
      var affiliateGoal: Double = 0
      var actualSales: Double = 0
      var salesNumber: Double = 0
      var salePH: Double = 0
      var sumSales: Double = 0
      var workHours: Double = 0
      var productsNum: Double = 0
      var servicePoint: Double = 0
      
  }
  
  class AffiliateModel: ObservableObject{
      
      @Published var affiliate: Affiliate
      
      private var session = SessionStore.shared
      
      init(){
          affiliate = self.session.affiliate
      }
      
  }
  </code></pre>
  <p>Titles:</p>
  <pre><code>enum AffiliateGoals: CaseIterable{
      case affiliateGoal, actualSales, salesNumber, salePH, sumSales, workHours, productsNum, servicePoint, presentOfGoal, hourlyDeal, hourlyOutput, averageDeal, averageIPT
      
      var title: String{
          switch self{
          case .affiliateGoal:
              return &quot;Affiliate Goal&quot;
          case .actualSales:
              return &quot;Actual Sales&quot;
          case .salesNumber:
              return &quot;Sales Number&quot;
          case .salePH:
              return &quot;Sales Per Hour&quot;
          case .sumSales:
              return &quot;Sales Summary&quot;
          case .workHours:
              return &quot;Work Hours&quot;
          case .productsNum:
              return &quot;Products Number&quot;
          case .servicePoint:
              return &quot;Service Point&quot;
          case .presentOfGoal:
              return &quot;Present Of Goal&quot;
          case .hourlyDeal:
              return &quot;Hourly Deal&quot;
          case .hourlyOutput:
              return &quot;Hourly Output&quot;
          case .averageDeal:
              return &quot;Average Deal&quot;
          case .averageIPT:
              return &quot;Average Items Per Transaction&quot;
          }
      }
  }
  </code></pre>
  <p>The Views:</p>
  <pre><code>struct SetAffiliateGoals: View {
      
      @EnvironmentObject var session: SessionStore
      
      @ObservedObject var model: AffiliateModel
      
      @Binding var show: Bool
      @State private var showAlert = false
      
      let goals = AffiliateGoals.self
      
      var body: some View {
          NavigationView{
              Form{
                  Section(header: Text(&quot;Fulfill the details:&quot;).padding(.top)){
                      SetGoalRow(title: goals.affiliateGoal.title, value: $model.affiliate.affiliateGoal)
                      SetGoalRow(title: goals.actualSales.title, value: $model.affiliate.actualSales)
                      SetGoalRow(title: goals.salePH.title, value: $model.affiliate.salePH)
                      SetGoalRow(title: goals.salesNumber.title, value: $model.affiliate.salesNumber)
                      SetGoalRow(title: goals.sumSales.title, value: $model.affiliate.sumSales)
                      SetGoalRow(title: goals.workHours.title, value: $model.affiliate.workHours)
                      SetGoalRow(title: goals.productsNum.title, value: $model.affiliate.productsNum)
                      SetGoalRow(title: goals.servicePoint.title, value: $model.affiliate.servicePoint)
                  }
              }
      }
  }
  
  </code></pre>
  <p>Because the values are <code>Double</code> I tried to create a binding String so the user won't need to press Return button every time he typing a value to apply.</p>
  <pre><code>struct SetGoalRow: View{
      
      @State var title: String
      @Binding var value: Double
      let numberFormatter = NumberFormatter()
      
      var amountProxy: Binding&lt;String&gt; {
          Binding&lt;String&gt;(
              get: { String(format: &quot;%.1f&quot;, value) },
              set: {
                  if let value = numberFormatter.number(from: $0) {
                      self.value = value.doubleValue
                  }
              }
          )
      }
      
      var body: some View{
          HStack(spacing: 8){
              Text(LocalizedStringKey(title + &quot;:&quot;))
                  .layoutPriority(1)
              TextField(LocalizedStringKey(&quot;&quot;), text: amountProxy)
                  .keyboardType(.decimalPad)
                  .multilineTextAlignment(.trailing)
          }
          .lineLimit(1)
      }
  
  }
  </code></pre>