我想要一个函数,对于任何给定的函数,它Error会给我一些描述
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"
}
}
Run Code Online (Sandbox Code Playgroud)
上面不是真正的代码,我不想要String描述,而是a Dictionary,但这在问题的上下文中并不重要.
问题是我不知道如何区分Errors是哪个子类,NSError哪个不是因为任何快速错误都可以桥接到NSError.有可能迅速吗?