Looks like Enumerations in Swift cannot be compared for equality. Here is the code I would expect to work:
let areEqual = MyEnum.SomeEnumValue == MyEnum.SomeEnumValue
However, this does not compile and throws error: Cannot invoke '==' with an argument list of type '(MyEnum, MyEnum)'
.
Is it possible to compare 2 Enumeration values using ==
operator or do I really write switch-case for that?
EDIT
Here is self containing example. Just past it to playground and you should see the compilation error.
import UIKit
enum MyEnum {
case SomeValue(Int)
case OtherValue(Double)
case ThirdValue
}
let areEqual = MyEnum.ThirdValue == MyEnum.ThirdValue
Looks a bit like Swift bug because it lets you compare Enumerations that has no associated values without complains. So I hope this is not expected behaviour (allowing to compare some Enumerations but not others).