К сожалению, вы не можете изменить тип параметра, потому что изменить бы интерфейс. Вы можете уйти с изменением возвращаемого типа метода на подтип, но вы не можете изменить параметр метода на подтип.
У вас есть один вариант действительно, динамичный бросок:
public func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
// use as? or as! to cast UITableViewCell to your desired type
}
Конечно, вы можете сделать то же самое несколькими способами, например, вы можете создать метод перенаправления:
public func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
self.tableView(tableView, willDisplayMyCell: cell as! MyCellClass, forRowAtIndexPath: indexPath)
}
private func tableView(tableView: UITableView, willDisplayMyCell myCell: MyCellClass, forRowAtIndexPath indexPath: NSIndexPath) {
// do something
}
и вы можете абстрактный, что в подпротокол из UITableViewDelegate
:
class MyTableViewCell : UITableViewCell {
}
protocol MyTableViewDelegate : UITableViewDelegate {
associatedtype CellClass: UITableViewCell
func tableView(
tableView: UITableView,
willDisplayMyCell cell: CellClass,
forRowAtIndexPath indexPath: NSIndexPath)
}
extension MyTableViewDelegate {
func tableView(
tableView: UITableView,
willDisplayCell cell: UITableViewCell,
forRowAtIndexPath indexPath: NSIndexPath) {
self.tableView(tableView, willDisplayMyCell: cell as! CellClass, forRowAtIndexPath: indexPath)
}
}
Прохладных тонкое g об этом заключается в том, что протокол является многоразовым, однако все это сводится к as?
или as!
динамическим приводом.
это протокол с полной логикой реализации в зависимости от вас. Как вы собираетесь переопределить его? –