I am trying to implement Equatable protocol in equalityClass, but showing Member operator '==' must have at least one argument of type 'eqaualityClass' .can any one explain whats going wrong here?
protocol Rectangle: Equatable {
var width: Double { get }
var height: Double { get }
}
class eqaualityClass:Rectangle{
internal var width: Double = 0.0
internal var height: Double = 0.0
static func == <T:Rectangle>(lhs: T, rhs: T) -> Bool {
return lhs.width == rhs.width && rhs.height == lhs.height
}
}
A more elegant solution:
You can use a protocol extension to have all your class/struct/enum entities adopting the Rectangle protocol conform to Equatable, like so:
You need to make your Rectangle protocol a class. Try like this:
or