Ideally I'd have the server implement the Equatable protocol but I ran into issues. Here's my code
protocol Server {
var ipAddress: String { get }
// simplified for this question
}
func ==<T:Server>(lhs: T, rhs: T) -> Bool {
return lhs.ipAddress == rhs.ipAddress
}
func !=<T:Server>(lhs: T, rhs: T) -> Bool {
return lhs.ipAddress != rhs.ipAddress
}
func ==<T:Server, U:Server>(lhs: T, rhs: U) -> Bool {
return lhs.ipAddress == rhs.ipAddress
}
func !=<T:Server, U:Server>(lhs: T, rhs: U) -> Bool {
return lhs.ipAddress != rhs.ipAddress
}
func doSomething(server0: Server, server1: Server) {
// I want to compare to Server objects
// !!! Compile Error !!!
// Binary operator '==' cannot be applied to two 'Server' operands
guard server0 == server1 else {
print("SAME BAD")
return
}
print("DO stuff")
}
Ultimately I just want to compare to abstract protocol objects against each other. Most of the other examples out there are comparing the concrete types.
Am I crazy for trying this or what? :P