0

I am attempting to create an add button using the following code:

@IBOutlet weak var userInput: UITextField! 
@IBAction func addMember(_ sender: UIButton) {
if (userInput.text != nil) && userInput.text != "" {
    list.append(userInput.text!)
    //userInput.placeholder = "Add more ?"
    userInput.text = ""
    }
}

1 Answers1

0

you could use optional binding inside your addMember IBAction Function like this:

if let text = userInput.text{
    if userInput.text!= "" {
         list.append(text)
         userInput.text = ""
    }
}