Swift docs say that automatic synthesis of Equatable
conformance is available for structs, and enums with associated values, only if conformance is declared in the original definition of the struct or enum, and not through an extension, in which case an implementation of the ==
operator must be provided.
However, the following code works.
struct Point {
var x: Double
var y: Double
}
extension Point: Equatable {}
print(Point(x: 10, y: 10) == Point(x: 5, y: 5)) // prints false
So does this.
enum Outcome {
case success
case failure(reason: String)
}
extension Outcome: Equatable {}
print(Outcome.failure(reason: "Chance") == Outcome.failure(reason: "Chance")) // prints true
Does anyone know where this feature is documented.
Thanks.