I have the following listing:
enum State: Equatable { case Loading case Finished case Error(message: String) } func ==(lhs: State, rhs: State) -> Bool {
I want to be able to compare enumeration members. I overloaded the == operator and it works, but there is a problem:
let state: State = .Loading // works just fine let thisWorks = state == .Finished // this does as well let thisWorks2 = state == .Error("Derp!") // this, however, does not, compiler error: "Could not find member 'Error'" let thisDoesnt = state == .Error
This seems to be a compiler limitation. I do not understand why I cannot refer to an enumeration element without its associated value. Apparently, I don't care about the error message associated with .Error , I just need to know if an error has occurred. This is possible with switch , so I don't know why regular statements are limited.
I must admit that I did not look very closely at Swift 2. Should I expect some improvements in the new version? Another question, until it is released, is there a workaround?
source share