Both the documentation on ErrorType and the description given when you command-click on ErrorType in Xcode give ErrorType as:
protocol ErrorType {
}Which is, apparently, a lie. Attempting to add ErrorType to a struct's conformances gives "does not conform to protocol 'ErrorType'" errors.
Inspecting any ErrorType using LLVM reveals that the ErrorType definition is really:
protocol ErrorType {
var _domain: String { get }
var _code: Int { get }
}Sure enough, if you implement these hidden methods, any type can conform to ErrorType.
Bringing me to my questions...
- Why is this requirement not exposed for us to use normally? Are we required to limit ErrorType to Swift enums and NSError for now?
- Related question: since ErrorType can extract an Int "tag" from an arbitrary enum, is there any public way to do the same without going enum -> ErrorType -> NSError -> code?