title: SwiftUI dynamically add/remove TextField with Stepper
body: <p>Hi all I'm new to SwiftUI and am trying to find a neat way to add or remove TextFields when either the plus or minus of a steeper is pressed.</p>
  <p>I currently have</p>
  <pre><code>@State private var answers: [String] = [&quot;&quot;, &quot;&quot;]
  Stepper(onIncrement: {
      if(numberOfAnswers &lt; 10){
          answers.append(&quot;&quot;)
          numberOfAnswers += 1
      }
      },
      onDecrement: {
          if(numberOfAnswers &gt; 2){
          answers.removeLast()
          numberOfAnswers -= 1
          }
      }) {
  ForEach(answers.indices, id: \.self) { index in
      TextField(&quot;Answer&quot;, text: $answers[index])
  }
  </code></pre>
  <p>However this results in an Index out of bounds exception when onDecrement is called.
  I have tried wrapping the String to conform to Identifiable (with the <code>@State</code> inside the struct declaration), using <code>ForEach(answers)</code> however this produces a warning stating that the variable will not be updated.</p>
  <p>I have tried solutions posted <a href="https://stackoverflow.com/questions/59060673/swiftui-foreach-index-out-of-range-error-when-removing-row">here</a> but to no avail.</p>
  <p>I do not need to persistently store the result of this, as it will be passed to a separate function making an API call on button press.</p>
  <p>Any help for this would be much appreciated.</p>