I want to make array with protocol elements call array extension method. The code in playground get error:
error: type 'ObjectProtocol' does not conform to protocol 'Equatable'
The code:
extension Array {
func good() {
}
}
protocol ObjectProtocol {
}
extension ObjectProtocol where Self: Equatable {
func isEqualTo(_ other: ObjectProtocol) -> Bool {
guard let otherX = other as? Self else { return false }
return self == otherX
}
}
extension Array where Element: Equatable {
func bad() {}
}
var protocolArray = [ObjectProtocol]()
var array = [1,3,2,5]
array.good() // OK
array.bad() // OK
protocolArray.good() // OK
protocolArray.bad() // error: error: type 'ObjectProtocol' does not conform to protocol 'Equatable'
Any way to achieve it?