Skip to content

Instantly share code, notes, and snippets.

@jonathanduty
Created June 29, 2018 12:28
Show Gist options
  • Save jonathanduty/7d555d5fdcf8de7d20e41b409f16d34f to your computer and use it in GitHub Desktop.
Save jonathanduty/7d555d5fdcf8de7d20e41b409f16d34f to your computer and use it in GitHub Desktop.
UIViewController+Extensions.swift
import UIKit
enum UIViewControllerDismissType {
case pop
case dismiss
}
extension UIViewController {
func presentAlertWithTitle(title: String = "Oops!", message: String, actions: [UIAlertAction] = [], preferredStyle: UIAlertControllerStyle = .alert, onComplete: ((KeystoneResultSimple) -> Void)? = nil) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: preferredStyle)
if actions.isEmpty {
let alertAction = UIAlertAction(title: "OK", style: .default, handler: { (alert) in
onComplete?(.success)
})
alertController.addAction(alertAction)
}
else {
actions.forEach({alertController.addAction($0)})
}
present(alertController, animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment