Skip to content

Instantly share code, notes, and snippets.

@bryanjclark
Created September 17, 2019 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanjclark/a45d1b1b8eb83c3318a7445dedfa7d50 to your computer and use it in GitHub Desktop.
Save bryanjclark/a45d1b1b8eb83c3318a7445dedfa7d50 to your computer and use it in GitHub Desktop.
UIAlertController + "Not Built Yet" helper
extension UIAlertController {
static func notBuiltYet(title: String? = "Haven't built this yet") -> UIAlertController {
let alertController = UIAlertController(
title: title,
message: "Not built yet. Sorry!",
preferredStyle: .alert
)
alertController.addAction(UIAlertAction.dismiss)
return alertController
}
static func infoAlert(title: String, message: String?) -> UIAlertController {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction.dismiss)
return alertController
}
}
extension UIViewController {
func presentNotBuiltYetAlert() {
let alert = UIAlertController.notBuiltYet()
self.present(alert, animated: true, completion: nil)
}
}
extension UIAlertAction {
static let dismissSecondary = UIAlertAction(title: "Dismiss", style: .default, handler: nil)
static let dismiss = UIAlertAction(title: "Dismiss", style: .cancel, handler: nil)
static let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
convenience init(title: String, urlString: String) {
let url = URL(string: urlString)!
self.init(title: title, style: .default) { _ in
guard UIApplication.shared.canOpenURL(url) else { return }
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment