【发布时间】:2017-06-17 18:13:55
【问题描述】:
我正在尝试创建 [petInfo : UIImage]() 类型的字典,但我收到了错误 Type 'petInfo' does not conform to protocol 'Hashable'。我的 petInfo 结构是这样的:
struct petInfo {
var petName: String
var dbName: String
}
所以我想以某种方式使其可散列,但它的所有组件都不是var hashValue: Int 所要求的整数。如果它的字段都不是整数,我怎样才能使它符合协议?如果我知道这个结构的所有出现都是唯一的,我可以使用dbName 吗?
【问题讨论】:
标签: swift dictionary swift3 hashable