I have an error enum like so:
public enum RequestError: Error, Equatable {
case httpError(HTTPStatus, data: Data?)
case networkError(URLError.Code)
case mappingError(DecodingError)
// some other cases
}
By defining functions like this:
public extension RequestError {
static func ~= (pattern: HTTPStatus, value: Self) -> Bool {
guard case .httpError(pattern, _) = value else { return false }
return true
}
}
… I used to be able to do this:
switch error {
case .requestFailed(.unauthorized): ...
case .requestFailed(.notConnectedToInternet): ...
}
In Xcode 12 this doesn't work anymore.
I can fix the latter of the two cases above by adding the type explicitly, but not the former:
switch error {
// Error: Cannot convert value of type 'RequestError' to specified type 'HTTPStatus'
case .requestFailed(HTTPStatus.unauthorized): ...
// Works!
case .requestFailed(URLError.notConnectedToInternet): ...
}
Apple Swift version 5.3 (swiftlang-1200.0.16.9 clang-1200.0.22.5)