Я пытаюсь создать ProfileCellController
, который можно использовать для настройки ячейки в моем UITableView
.
Поскольку моя таблица может иметь несколько типов ячеек, я надеялся использовать обобщенные значения для установки введите необходимую ячейку и используйте метод configure для установки реквизита.
Это то, что у меня есть:
import UIKit
public protocol ProfileLoadedView {
func display(_ viewModel: ProfileViewModel)
}
public class SingleLineCell: UITableViewCell { }
public class MultiLineWithIconCell: UITableViewCell { }
public final class ProfileCellController<T> where T: UITableViewCell {
private var cell: T?
func view(in tableView: UITableView) -> UITableViewCell {
cell = tableView.dequeueReusableCell()
return cell!
}
}
extension ProfileCellController: ProfileLoadedView where T: SingleLineCell {
public func display(_ viewModel: ProfileViewModel) {
}
}
extension ProfileCellController: ProfileLoadedView where T: MultiLineWithIconCell {
public func display(_ viewModel: ProfileViewModel) {
}
}
extension UITableView {
func dequeueReusableCell<T: UITableViewCell>() -> T {
let identifier = String(describing: T.self)
return dequeueReusableCell(withIdentifier: identifier) as! T
}
}
Однако второе расширение имеет ошибку
Конфликт соответствия ProfileCellController с протоколом ProfileLoadedView; не может быть более одного соответствия, даже с разными условными границами
Возможно ли достичь этого?