I have a Textfield and a button. Wenn the button is pressed, a function is triggered that stores the items that are typed in the TextField into an Array and then outputs the current contents of the Array to the console. How to store the input from the TextField into an array of strings? I've just started learning Swift and need your help. Thanks a lot in advance!
@IBOutlet weak var inputEntered: UITextField!
@IBAction func buttonAddToList(_ sender: UIButton) {
var shoppingList: [String] = []
let item = inputEntered.text
shoppingList.append(item)
for product in shoppingList {
print(product)
}
}
var shoppingList: [String] = []out of your methodbuttonAddToListlet item = inputEntered.text!