I want a function which, for any given Error
, will give me some description of it
protocol CustomError { }
func customDescription(_ error: Error) -> String {
switch error {
case let customError as CustomError:
return "custom error"
case ???:
return "not subclass of NSError"
case let nsError as NSError:
return "subclass of NSError"
}
}
Above is not the real code, and I don't want a String
description, but a Dictionary
, but this is not important in context of the question.
The problem is I don't know how to distinguish Error
s which is subclass of NSError
and which is not because any swift error could be bridged to NSError
. Is it possible in swift?