Created
December 13, 2019 14:23
-
-
Save andr3a88/c7e5ba670063ae7e9bb67d959136175c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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