У меня есть два протокола: один для ViewModel и один для ConfigurableView, который принимает тип ViewModel в качестве связанного типа.:
public protocol ViewModel {}
public protocol ConfigurableView {
associatedtype ViewModelType: ViewModel
func configure(with viewModel: ViewModelType)
}
В моем методе, который настраивает абстрактное представление с абстрактной моделью:
let viewModel = getMyViewModel() // returns ViewModel
if let configurableView = cell as? ConfigurableView {
configurableView.configure(with: viewModel)
}
Я получаю «Протокол« ConfigurableView »может использоваться только как общее ограничение, поскольку он имеет требования к собственному или связанному типу».
Как мне сообщить компилятору, что я хочу настроить представление с любым типом, связанным с этим экземпляром, если это экземпляр ConfigurableView?