【发布时间】:2015-11-15 07:28:03
【问题描述】:
游乐场代码在这里
class ProductModel {
var productID : Int = 0
init(id:Int) {
productID = id
}
}
protocol GenericListProtocol {
typealias T = ProductModel
var list : [T] { get set }
var filteredlist : [T] { get set }
func setData(list : [T])
}
extension GenericListProtocol {
func setData(list: [T]) {
list.forEach { item in
guard let productItem = item as? ProductModel else {
return
}
print(productItem.productID)
}
}
}
class testProtocol {
class func myfunc<N:GenericListProtocol>(re:N){
var list : [ProductModel] = [ProductModel(id: 1),ProductModel(id: 2),ProductModel(id: 3),ProductModel(id: 4)]
re.setData(list)
}
}
但在re.setData(list)行内
得到编译错误:
无法将“[ProductModel]”类型的值转换为预期参数 输入“[_]”。
我的问题是如何在GenericListProtocol 中使用 setData 方法?
任何人都可以提供帮助,我们将不胜感激。
【问题讨论】: