更新时间:2023-02-15 19:47:55
有关包含()
函数工作产品
类应该实现 Equatable
的协议。那是唯一的方式,我们可以检查两个元素是否相等。
For contains()
function to work the Products
class should implement Equatable
protocol. That's the way only we can check whether two elements are equal.
class Products : Equatable {
var name:String = ""
var number:Int = 0
init(name: String, number: Int) {
self.name = name
self.number = number
}
}
func ==(lhs: Products, rhs: Products) -> Bool
{
return lhs.name == rhs.name && lhs.number == rhs.number
}