I have following class with enum defined in it:
public class MyError: NSError {
public enum Type: Int {
case ConnectionError
case ServerError
}
init(type: Type) {
super.init(domain: "domain", code: type.rawValue, userInfo: [:])
}
}
When I try to check the error later in my tests like:
expect(error.code).to(equal(MyError.Type.ConnectionError.rawValue))
I get the compilation error: Type MyError.Type has no member ConnectionError
Any ideas what I am doing wrong here?
The problem is that Type
is a Swift keyword and your custom Type
confuses the compiler.
In my tests in a Playground your code generated the same error. The solution is to change Type
for any other name. Example with Kind
:
public enum Kind: Int {
case ConnectionError
case ServerError
}
init(type: Kind) {
super.init(domain: "domain", code: type.rawValue, userInfo: [:])
}
Then
MyError.Kind.ConnectionError.rawValue
works as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With