Created
May 22, 2018 21:13
-
-
Save mxcl/906cf839001b055980f67bc84c25d356 to your computer and use it in GitHub Desktop.
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
public extension Error { | |
var legibleDescription: String { | |
if let error = self as? LocalizedError, let description = error.errorDescription { | |
return description | |
} else if (self as AnyObject).isKind(of: NSError.self) { | |
return localizedDescription | |
} else { | |
let mirror = Mirror(reflecting: self) | |
switch mirror.displayStyle { | |
case .enum?: | |
return "\(type(of: self)).\(self)" | |
case .class?: | |
return "\(self)" | |
default: | |
return String(describing: self) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment