I am trying to display a list of items on a shopping list. These items are added from two text fields (description and quantity). For some reason, I am not able to get the array to keep the previous items, instead, the previous items in the array disappear and the only item that shows was the most recent item entered. Can someone help me understand where I have gone wrong? Here is the code I have:
@IBAction func add(_ sender: UIButton) {
var shoppingList = [String]()
if let x = descriptionField.text{
if let y = quantityField.text{
if x != "" && y != "" {
if isStringAnInt(string: y){
shoppingList.append("\(y) x \(x)")
}else{
[...]