Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SashaTsebrii/f5a3b0a9f360befacf4a6c617e5569fc to your computer and use it in GitHub Desktop.
Save SashaTsebrii/f5a3b0a9f360befacf4a6c617e5569fc to your computer and use it in GitHub Desktop.
Alert
// Default alert
let alert = UIAlertController(title: "Did you bring your towel?", message: "It's recommended you bring your towel before continuing.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { action in
print("Yay! You brought your towel!")
}))
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
self.present(alert, animated: true)
// Alert with text fields
let alert = UIAlertController(title: "What's your name?", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
alert.addTextField(configurationHandler: { textField in
textField.placeholder = "Input your name here..."
})
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
if let name = alert.textFields?.first?.text {
print("Your name: \(name)")
}
}))
self.present(alert, animated: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment