我试图在 Swift 3 预览版 6 中Array<String>
符合Hashable
:
extension Array: Hashable where Element: Hashable {
public var hashValue: Int {
var hashValue = 0
for element in self {
hashValue ^= element.hashValue
}
return hashValue
}
}
var data = Dictionary<Array<String>, Any>()
但我收到以下错误,不知道为什么:
ERROR at line 4, col 1: extension of type 'Array' with constraints cannot have an inheritance clause
extension Array: Hashable where Element: Hashable {
^
如何使数组可散列?