2017-10-15 105 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

我做錯了什麼?

回答