Created
September 17, 2019 20:12
-
-
Save bryanjclark/a45d1b1b8eb83c3318a7445dedfa7d50 to your computer and use it in GitHub Desktop.
UIAlertController + "Not Built Yet" helper
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 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