Created
November 20, 2015 00:45
-
-
Save stuartbreckenridge/84f75d52db444b8e4c46 to your computer and use it in GitHub Desktop.
Remove boilerplate when displaying UIAlertControllers from a UIViewController
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
protocol UIAlertControllerErrorDisplay | |
{ | |
func showAlertControllerWithError(error:NSError) | |
} | |
extension UIViewController:UIAlertControllerErrorDisplay | |
{ | |
func showAlertControllerWithError(error:NSError) | |
{ | |
NSOperationQueue.mainQueue().addOperationWithBlock { () -> Void in | |
let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .Alert) | |
alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default, handler: nil)) | |
self.presentViewController(alert, animated: true, completion: nil) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment