Skip to content

Instantly share code, notes, and snippets.

@andr3a88
Created December 13, 2019 14:23
Show Gist options
  • Save andr3a88/c7e5ba670063ae7e9bb67d959136175c to your computer and use it in GitHub Desktop.
Save andr3a88/c7e5ba670063ae7e9bb67d959136175c to your computer and use it in GitHub Desktop.
import Foundation
/// A protocol to present an alert controller
protocol AlertPresentable where Self: UIViewController {
/// Present an alert controller
///
/// - Parameters:
/// - title: The alert title
/// - message: The alert message
/// - actions: An array of actions
/// - completion: The completion handler of the presentaetion action
func presentAlert(title: String, message: String, actions: [UIAlertAction], completion: (() -> Void)?)
}
extension AlertPresentable {
func presentAlert(title: String, message: String, actions: [UIAlertAction], completion: (() -> Void)? = nil) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
actions.forEach { alert.addAction($0) }
present(alert, animated: true, completion: completion)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment