确定这里的数组的问题:斯威夫特 - 通用无法追加到超类
说,我们有持有ChildClasses
class ParentClass {
var list: [ChildClass<UITableViewCell>] = []
func append<T>(cell: T) where T: UITableViewCell {
let child = ChildClass<T>()
list.append(child)
}
}
的阵列和子类的父类,
class ChildClass<T> where T: UITableViewCell {
var obj: T!
}
两个类的是通用的类型(T)常是类型的UITableViewCell
现在如果你尝试建立它,你会得到这个错误:
Cannot convert value of type ChildClass< T > to expected argument type ChildClass< UITableViewCell >
但如果T是的UITableViewCell的子类,应该不是能够到T转换???
由于事先
密切相关(欺骗?):如何存放Class类型的值在Swift中类型为\ [String:Class \]的字典中](http://stackoverflow.com/q/38590548/2976878) –
Hamish
这真的很难找到这个问题,如果你认为它是重复的,我同意 –