Skip to content

Instantly share code, notes, and snippets.

@enigmatic7earth
Created July 20, 2018 13:41
Show Gist options
  • Save enigmatic7earth/0f4d1e36db678af60990b23e323d8ada to your computer and use it in GitHub Desktop.
Save enigmatic7earth/0f4d1e36db678af60990b23e323d8ada to your computer and use it in GitHub Desktop.
Autodismiss alert
// the alert view
let alert = UIAlertController(title: "", message: "alert disappears after 5 seconds", preferredStyle: .alert)
self.present(alert, animated: true, completion: nil)
// change to desired number of seconds (in this case 5 seconds)
let when = DispatchTime.now() + 5
DispatchQueue.main.asyncAfter(deadline: when){
// your code with delay
alert.dismiss(animated: true, completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment