gpt4 book ai didi

ios - 不能为类型值添加下标

转载 作者:行者123 更新时间:2023-11-30 12:45:25 24 4
gpt4 key购买 nike

所以我创建了一个名为 Artist 的类,我想创建一个 [Artist: Int] 类型的键值字典,但是当我尝试时

dictionary[Artist] = 1

我得到 Cannot subscript value of type Artist

这是我的 Artist 类和 Hashable 函数

class Artist: Hashable {
let name: String
let lastName: String
var hashValue: Int {
return NSUUID().UUIDString.hashValue
}

init(name: String, lastName: String) {
self.name = name
self.lastName = lastName
}

}

func ==(lhs: Artist, rhs: Artist) -> Bool {
return lhs.hashValue == rhs.hashValue
}

最佳答案

所以我只是没有注意到我试图添加类 Artist 而不是艺术家对象作为字典的键

关于ios - 不能为类型值添加下标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41695683/

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