-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
@luketomlinson here is an idea from my own experiment along these lines:
You could introduce a new protocol that CellConfigurable inherits from like this:
protocol AnyCellConfigurable {
func configure(with viewModel: CellViewModelType) // can also be just Any
}
protocol CellConfigurable: AnyCellConfigurable {
associatedtype ViewModelType: CellViewModelType
func configure(with viewModel: ViewModelType)
}
extension CellConfigurable {
func configure(with viewModel: CellViewModelType) {
// this will crash only in the same case that InstrumentViewController. configureCell reaches the default case with the fatalError
configure(with: viewModel as! ViewModelType)
}
Assuming that your tableView is configured to dequeue only cells of type AnyCellConfigurable, you can then replace configureCell(_ cell: UITableViewCell, cellViewModel: CellViewModelType) with just a call like cell.configure(with: viewModel) and they should be functionally equivalent with less boiler plate in the second case.
Metadata
Metadata
Assignees
Labels
No labels