试图创建一个不可变的字典.我们的想法是拥有不可变的键和值数组,然后将它们传递给a
Dictionary constructor: let dict = Dictionary(aStringArray, aSameLengthDoubleArray)
但是,以下代码给出了编译时错误.
extension Dictionary {
init<T:Hashable,U>(keys: [T], values: [U]) {
self.init()
for (index, key) in keys.enumerate() {
self[key] = values[index]
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
错误:无法下标"Dictionary"类型的值,索引类型为"T"self [key] = values [index]
有人可以对此有所了解吗?