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

标签 ios swift dictionary

所以我创建了一个名为 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/

相关文章:

c# - 在我的代码中的字典中使用许多字典

ios - Realm:如何在 Realm 中添加两个 Result<(Object)>

ios - Scene Kit 中铰链关节的奇怪摇晃

java - MonoTouch + IKVM 项目中的 JIT 编译问题

arrays - 字符串数组顺序错误

swift - 无法从连接到 XIB 的 UIView 执行 segue

ios - 应用程序共享提供零数据

ios - 使用 plist 在 TableView 之间传递数据

Python - mysqlDB,sqlite 结果作为字典

python - 将 dict 项映射到 pandas 系列时忽略大小写