Skip to content

Instantly share code, notes, and snippets.

@kashfifahim
Last active January 24, 2018 03:25
Show Gist options
  • Save kashfifahim/2455249da4710120f3e79d1bcf9c454a to your computer and use it in GitHub Desktop.
Save kashfifahim/2455249da4710120f3e79d1bcf9c454a to your computer and use it in GitHub Desktop.
Notes on alerts
// first let's create a function for the alert
// remember to connect this code to a button on the storyboard.
@IBAction func showAlert() {
// We have to (1) set up the alert
// then (2) we have to set up the action to the alert (the button inside the alert)
let alert = UIAlertController(title: "Hello, World!", message: "This is my first alert!", prefferredStyle: .alert)
let action = UIAlertAction(title: "Awesome", style: .default, handler: nil)
// (3) Now we have to add the action to the alert
alert.addAction(action)
// (4) Now we program this alert's presentation
present(alert, animated: true, completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment