Created
December 5, 2018 07:11
-
-
Save cumanzor/ac23c592413d709c95e1510c52c32c62 to your computer and use it in GitHub Desktop.
Revisions
-
cumanzor created this gist
Dec 5, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ extension UIViewController { func showAlert(withTitle title: String, message : String, withActions actions:[UIAlertAction] = [], withCompletion c:(()->())?=nil) { let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) if actions.isEmpty{ // default ok action let defaultAction = UIAlertAction(title: "Ok", style: .default) alertController.addAction(defaultAction) } for action in actions{ alertController.addAction(action) } self.present(alertController, animated: true, completion: c) } } // use it like this: // show a simple message with an ok action that just dismisses the alert showAlert(withTitle: "Error", message: "Unable to do stuff.") // add an action (pop the VC) let backAction = UIAlertAction(title: "Ok", style: .default) { (action) in self.navigationController?.popViewController(animated: true) } showAlert(withTitle: "Error", message: "Unable to do stuff, please return and try again.", withActions: [backAction])