【发布时间】:2014-10-02 23:28:38
【问题描述】:
我收到一个编译错误,因为编译器认为我的元组中的“键”与泛型数组的类型不同。知道为什么吗?
class MyClass <K: Hashable, V> {
let keys = [K]()
subscript(index: Int) -> (key: K, value: V) {
set(newValue) {
// also tried newValue.key!
keys[index] = newValue.key
}
}
}
【问题讨论】:
-
顺便说一句,为什么你在 setter 中有
return语句?它也应该给你一个编译错误? -
@Keenle 抱歉,我的问题打错了,实际代码是正确的