0

I have a class of the following type:

class OptionViewModel<T: SelectableOption>: ViewModel

At some other point I need to be able to do something like the following:

func configure(viewModel: ViewModel) {
  guard let model = model as? OptionViewModel else { return }
}

I don't care at this point what the generic type is (only that it conforms to the protocol) but I can't get this line to compile due to having to supply a concrete type here (which I don't know - currently I have 4 possibilities).

Generic parameter 'T' could not be inferred in cast to 'OptionViewModel'

I'm looking for any suggestions on how to restructure this, or get around my issue. Thanks!

BinaryGuy
  • 1,246
  • 1
  • 15
  • 29

0 Answers0