在 Swift 中是否不可能将对象身份与协议类型进行比较?我正在尝试找到一种内置的方法来做到这一点。这是我的例子:
protocol MyProtocol {
var propertyFoo: Int { get set }
}
class MyProtocolImpl: MyProtocol {
var propertyFoo = 100
func test(arg: MyProtocol) {
if arg === self { // error
print("Same object")
} else {
print("Different object")
}
}
}
我收到以下错误:
二元运算符“===”不能应用于“MyProtocol”和“MyProtocolImpl”类型的操作数