jlandon / Alexandria

A library of Swift extensions to turbocharge your iOS development.
https://jlandon.github.io/Alexandria
MIT License
65 stars 8 forks source link

add UIAlertController extensions #32

Closed jlandon closed 7 years ago

jlandon commented 7 years ago

A few simple extensions on UIAlertController

Individual examples:

controller.addAction(UIAlertAction(title: "Ok", style: .default)) // before
controller.addAction(title: "Ok")                                 // after

UIAlertController(title: "Title", message: nil, preferredStyle: .alert) // before
UIAlertController.alert(title: "Title")                                 // after

UIAlertController(title: "Title", message: nil, preferredStyle: .actionSheet) // before
UIAlertController.actionSheet(title: "Title")                                 // after

UIViewController.current?.present(controller, animated: true) // before
controller.present()                                          // after

Full example:

// before
let controller = UIAlertController(title: "Title", message: nil, preferredStyle: .alert)
controller.addAction(UIAlertAction(title: "Ok", style: .default))
controller.addAction(UIAlertAction(title: "Cancel", style: .cancel))
UIViewController.current?.present(controller, animated: true)

// after
UIAlertController.alert(title: "Title")
                 .addAction(title: "Ok")
                 .addAction(title: "Cancel", style: .cancel)
                 .present()
hsoi commented 7 years ago

Or you COULD just use HEAlert 😁

hsoi commented 7 years ago

We'll leave the PR open for a couple more days, in case anyone else has comments.