I tried this piece of code:
import Foundation
protocol P: Equatable {}
class T {
var p: any P
init(_ pp: any P) {
self.p = pp
}
func update(_ pp: any P) {
if pp != p {
p = pp
}
}
}
But I'm getting an error:
Binary operator '!=' cannot be applied to two 'any P' operands
Why is that and how can I solve this? Thank you for your help
You cannot equate existentials. You need one concrete
Equatabletype.This method relies on implicitly opening one of the existential operands, and unfortunately cannot be replicated by an operator (e.g.
!=?) yet.