2017-10-15 106 views
0

嘿,我得到了ConfigurationType协议斯威夫特 - 配置不同的细胞以同样的方式

protocol ConfigurationType {} 

和我自己的细胞类

class ConfigurableCell<T: ConfigurationType>: UITableViewCell { 
    func configure(with config: T) {} 
} 

我所有的细胞ConfigurableCell继承,我想创建CellModules,这我tableView会使用。

protocol CellModule { 
    associatedtype Config: ConfigurationType 
    associatedtype Cell: ConfigurableCell<Config> 
    var config: Config { get set } 
} 
extension CellModule { 
    init(_ config: Config) { 
     self.config = config 
    } 
    func dequeueCell(_ tableView: UITableView) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell() as Cell 
     cell.configure(with: config) 
     return cell 
    } 
} 

目标是为细胞创造模块这样

struct GoalTitleCellModule: CellModule { 
    typealias Cell = GoalTitleCell 
    var config: GoalTitleConfiguration 
} 

但Xcode的抱怨 “类型 'GoalTitleCellModule' 不符合协议 'CellModule'”。

enter image description here

我做错了什么?

回答