I don\'t think this can be done but I\'ll ask anyway. I have a protocol:
protocol X {}
And a class:
class Y:X {}
All people who say that you can't implement Equatable
for a protocol just don't try hard enough. Here is the solution (Swift 4.1) for your protocol X
example:
protocol X: Equatable {
var something: Int { get }
}
// Define this operator in the global scope!
func ==(l: L, r: R) -> Bool {
return l.something == r.something
}
And it works!
class Y: X {
var something: Int = 14
}
struct Z: X {
let something: Int = 9
}
let y = Y()
let z = Z()
print(y == z) // false
y.something = z.something
pirnt(y == z) // true
The only problem is that you can't write let a: X = Y()
because of "Protocol can only be used as a generic constraint" error.