Skip to content

Instantly share code, notes, and snippets.

@SlappyAUS
Last active October 9, 2020 23:49
Show Gist options
  • Save SlappyAUS/aafc62615537b677a1795855c2338f14 to your computer and use it in GitHub Desktop.
Save SlappyAUS/aafc62615537b677a1795855c2338f14 to your computer and use it in GitHub Desktop.
Alert with TextField #ui
@IBAction func addButtonPressed(_ sender: UIBarButtonItem) {
let alert = UIAlertController(title: "Add New Todoey Item", message: "", preferredStyle: .alert)
var textField: UITextField? = nil
let action = UIAlertAction(title: "Add Item", style: .default) { (action) in
if let safeTextField = textField {
print(safeTextField.text ?? "")
}
}
alert.addTextField { (alertTextField) in
alertTextField.placeholder = "Create new item"
textField = alertTextField
}
alert.addAction(action)
present(alert, animated: true, completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment