title: Swift- How to add onto arraylist next index everytime save button is pressed
body: <p>Hi my question is how can I store a string value which contails all textfield input into an array with new index every time I press save. I have created some code below however I think its overriding the first index.</p>
  
  <pre><code>@IBAction func Save (_ sender: UIButton){
  let firstextfield = textfield1.text
  let secondtextfield = textfield2.text
  
  let allText = firsttextfield! + "," + secondtextfield!
  var myArray = [String]()
  var index : Int = 0
  
  while (myArray.count) &lt;= index {
     myArray.insert(allText, at: index)
  
  }
  index +=
  
  
  for element in myArray{
   print(element)
   }
  
  
  }
  </code></pre>
  
  <p>input: firsttextfield = 9.22 and secondtextfield = 91.2
  save button is then pressed.</p>
  
  <p>output: </p>
  
  <pre><code>Optional ("9.22,91.2")
  Optional ("")
  </code></pre>
  
  <p>if i were to then change the values of my textfields to firsttextfield = 0.2 and secondtextfield = 20.2</p>
  
  <p>I get output : </p>
  
  <pre><code>Optional ("0.2,20.2")
  Optional ("")
  </code></pre>
  
  <p>I dont want it to overide the array but to add onto it so expected output:</p>
  
  <pre><code>Optional ("9.22,91.2")
  Optional ("0.2,20.2")
  </code></pre>
  
  <p>Any tips are welcome as I am new to coding.</p>