I would like to test the equivalency of a couple variables of enumeration types, like this:
enum AnEnumeration {
The Swift proposal
has been accepted and implemented in Swift 4.1 (Xcode 9.3):
... synthesize conformance to Equatable/Hashable if all of its members are Equatable/Hashable.
therefore it suffices to
... opt-in to automatic synthesis by declaring their type as Equatable or Hashable without implementing any of their requirements.
In your example – since String
is Equatable
– it will suffice to declare
enum AnEnumeration: Equatable {
case aSimpleCase
case anotherSimpleCase
case aMoreComplexCase(String)
}
and the compiler will synthesize a suitable ==
operator.