鉴于一些协议:
protocol CellConfigurable {
typealias CellType
func configureCell(type: CellType)
}
具体课程:
class SomeCellConfigClass: CellConfigurable {
typealias CellType = SomeUITableViewCellSubclass
func configureCell(type: CellType) {
// do something
}
}
你如何将一个物体投射到T? e.g。
let cell = // dequeue a cell
let cellConfigObj = SomeCellConfigClass()
// can't do the following because cell is of type UITableViewCell
// and it expects a type of CellType
// someObj.configureCell(cell)
// So, we need to cast cell to CellType...but how? The following doesn't work
if let cell = cell as? someObj.CellType {
someObj.configureCell(cell)
}