如何使Array <string> Hashable?

时间:2016-08-18 15:03:01

标签: swift protocols swift3 hashable

我试图让Array<String>符合Hashable,在Swift 3预览版6中:

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 {
^    

如何使阵列可以缓存?

0 个答案:

没有答案