Last active
January 8, 2018 21:12
-
-
Save farnscosnippet/1029126444f3cd70cfc71ccc3741a4d4 to your computer and use it in GitHub Desktop.
SWIFT - Generic Alert
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 characters
| // Error Alert - Usage Example: showAlert(withTitle: "Oops", message: "Please fill in both gravity fields.", viewController: self) | |
| func showAlert(withTitle title: String, message: String, viewController: UIViewController) { | |
| if viewController.presentedViewController == nil { // Prevent multiple alerts at the same time | |
| let localizedTitle = NSLocalizedString(title, comment: "") | |
| let localizedMessage = NSLocalizedString(message, comment: "") | |
| let alert = UIAlertController(title: localizedTitle, message: localizedMessage, preferredStyle: .alert) | |
| let action = UIAlertAction(title: "OK", style: .default, handler: nil) | |
| alert.addAction(action) | |
| viewController.present(alert, animated: true, completion: nil) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment