gpt4 book ai didi

swift - 在 Swift 中等价

转载 作者:搜寻专家 更新时间:2023-10-31 22:34:05 24 4
gpt4 key购买 nike

<分区>

我正在尝试使用 Swift 结构定义 Equatable。我在 func == 行收到一条错误消息,说 Operators are only allowed at global scope

struct ShoppingList {

var shoppingListId :NSNumber
var title :String

init(title :String) {

self.title = title
self.shoppingListId = NSNumber(integer: 0)
}
}

extension ShoppingList {

public func ==(lhs :ShoppingList, rhs :ShoppingList) -> Bool {
return lhs.title == rhs.title
}

}

我错过了什么?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com