Skip to content

Instantly share code, notes, and snippets.

@stuartbreckenridge
Created November 20, 2015 00:45
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 stuartbreckenridge/84f75d52db444b8e4c46 to your computer and use it in GitHub Desktop.
Save stuartbreckenridge/84f75d52db444b8e4c46 to your computer and use it in GitHub Desktop.
Remove boilerplate when displaying UIAlertControllers from a UIViewController
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