I would like to add validation on my hardcode data which known as itemArray Below are my screenshot that current alert view here
These are my codes
@IBAction func adDButtonPressed(_ sender: UIBarButtonItem) {
var textField = UITextField()
let alert = UIAlertController(title: "Add Email", message: "", preferredStyle: .alert)
let cancel = UIAlertAction(title: "cancel", style: .default) { (action) -> Void in
print("Cancel button tapped")
}
let action = UIAlertAction(title: "Add", style: .default) { (action) in
self.itemArray.append(textField.text!)
self.defaults.set(self.itemArray, forKey: "EmailArray")
self.tableView.reloadData()
}
alert.addTextField { (alertTextField) in
alertTextField.placeholder = "Create New Email"
textField = alertTextField
}
alert.addAction(action)
alert.addAction(cancel)
present(alert, animated: true, completion: nil)
}
}
to all swift experts, may I know is there any way for me too add validation such as alert textfield == "0" disable the add function for the users. your help is highly appreciated!