Attempting to match types CustomErrorwith compatible ones (ErrorType, NSError) leads to the loss of a dictionary of user information:
class CustomError: NSError {}
let error = CustomError(domain: "com.customerrorexample", code: 500, userInfo: [NSLocalizedDescriptionKey: "A great description"])
then
((error as ErrorType) as NSError).localizedDescription
However, this will print the correct description:
((error as ErrorType) as! CustomError).localizedDescription
How is it that the ((CustomError as ErrorType) as NSError)userInfo dictionary is losing? How can I get around this, knowing that my actual code will accept the input ErrorTypeand print it localizedDescription- which should be accurate regardless of the NSError subclass?
Edit
See my own answer here: stack overflow . Still not the best solution, feel free to offer the best.
source
share