Skip to content

Instantly share code, notes, and snippets.

@0ber
Created September 5, 2016 19:50
Show Gist options
  • Save 0ber/9ac1fde8777ead27e4c4c4ba2a0d9352 to your computer and use it in GitHub Desktop.
Save 0ber/9ac1fde8777ead27e4c4c4ba2a0d9352 to your computer and use it in GitHub Desktop.
protocol SwiftyAlertController {
static func actionSheet(title: String?, message: String?, actions: [EasyAlertControllerAction]) -> UIAlertController
static func alert(title: String?, message: String?, actions: [EasyAlertControllerAction]) -> UIAlertController
}
extension SwiftyAlertController where Self: UIAlertController {
static func actionSheet(title: String? = nil, message: String? = nil, actions: [EasyAlertControllerAction]) -> UIAlertController {
let alert = UIAlertController(title: title, message: message, preferredStyle: .ActionSheet)
actions.forEach { alert.addAction($0.action) }
return alert
}
static func alert(title: String? = nil, message: String? = nil, actions: [EasyAlertControllerAction]) -> UIAlertController {
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
actions.forEach { alert.addAction($0.action) }
return alert
}
}
extension UIAlertController: SwiftyAlertController {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment