Skip to content

Instantly share code, notes, and snippets.

@khawajafarooq
Created December 7, 2017 10:42
Show Gist options
  • Save khawajafarooq/93ad5c7909e458609578ef1dc306ec4f to your computer and use it in GitHub Desktop.
Save khawajafarooq/93ad5c7909e458609578ef1dc306ec4f to your computer and use it in GitHub Desktop.
Error extension to support UIAlertController
import UIKit
/// Extending error to make it alertable
extension Error {
/// displays alert from source controller
func alert(with controller: UIViewController) {
let alertController = UIAlertController(title: "Oops ❗️", message: "\(self)", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(okAction)
controller.present(alertController, animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment