geri222
11/20/2018 - 7:04 PM

UIAlertController with UIAlertAction

UIAlert with UIAction and Textfield input.

var textField = UITextField()

let alert = UIAlertController(title: "Add New Todoey Item", message: "", preferredStyle: .alert)

let action = UIAlertAction(title: "Add Item", style: .default) { (action) in
    
    self.itemArray.append(textField.text!)
    
}

alert.addTextField { (alertTextField) in
    
    alertTextField.placeholder = "Create new item"
    textField = alertTextField
    
}

alert.addAction(action)
present(alert, animated: true, completion: nil)