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
let actionSheet = UIAlertController.actionSheet(actions: [ | |
.Default(title: "Default", handler: { _ in print("tap")}), | |
.Destructive(title: "Destructive", handler: { _ in print("tap")}), | |
.Cancel(title: "Cancel", handler: nil) | |
]) | |
presentViewController(alert, animated:true, completion:nil) |
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
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) } |
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
extension SwiftyActions { | |
var action: UIAlertAction { | |
switch self { | |
case .Default(let title, let handler): return UIAlertAction(title: title, style: .Default, handler: handler) | |
case .Cancel(let title, let handler): return UIAlertAction(title: title, style: .Cancel, handler: handler) | |
case .Destructive(let title, let handler): return UIAlertAction(title: title, style: .Destructive, handler: handler) | |
} | |
} | |
} |
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
enum SwiftyActions { | |
case Default(title: String?, handler:((UIAlertAction) -> Void)?) | |
case Cancel(title: String?, handler:((UIAlertAction) -> Void)?) | |
case Destructive(title: String?, handler:((UIAlertAction) -> Void)?) | |
} |
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
let actionSheet = UIAlertController(title: "title", message: "message", preferredStyle: .ActionSheet) | |
let action = UIAlertAction(title: "default", style: .Default, handler: {_ in print("tap")}) | |
let cancel = UIAlertAction(title: "cancel", style: .Cancel, handler: {_ in print("tap")}) | |
let destructive = UIAlertAction(title: "action", style: .Destructive, handler: {_ in print("tap")}) | |
actionSheet.addAction(action) | |
actionSheet.addAction(cancel) | |
actionSheet.addAction(destructive) |