title: How to resolve generic property in protocol with associatedtype?
body: <p>Idea is to share the common code between <code>UITableView</code> and <code>UICollectionView</code> and their viewModels. So I have a baseCollectionsViewModel which is a generic class and looks like</p>
  <pre><code>class BaseCollectionsViewModel&lt;T: BasicTrackDataExtractorProtocol&gt; {
      var baseTrackResponse: T?
      ...
  }
  </code></pre>
  <p>Now I would like to have a <code>BaseCollectionsView</code> which holds <code>BaseCollectionsViewModel</code>. Because its a <code>UITableView</code> and <code>UICollectionView</code> I cant have a common base class among them so I decided to go in the direction of protocol to work around multiple inheritance</p>
  <pre><code>protocol BaseCollectionsViewProtocol {
      associatedtype dataExtractorType: BasicTrackDataExtractorProtocol
      var viewModel: BaseCollectionsViewModel&lt;dataExtractorType&gt;! { get }
      //all other common properties and logic here
  }
  </code></pre>
  <p>Finally when I try to use this protocol in my final class</p>
  <pre><code>final class TrackingTableViewModel: BaseCollectionsViewModel&lt;TrackOrderV3&gt; {
       
  }
  
  final class TrackingTableView: UITableView,BaseCollectionsViewProtocol {
      var viewModel: TrackingTableViewModel!
      typealias dataExtractorType = TrackOrderV3
      //other code
  }
  </code></pre>
  <p>Compiler complains that <code>TrackingTableView</code> does not confirm to <code>BaseCollectionsViewProtocol</code> and keeps adding</p>
  <pre><code>final class TrackingTableView: UITableView,BaseCollectionsViewProtocol {
      var viewModel: BaseCollectionsViewModel&lt;TrackOrderV3&gt;!
      typealias dataExtractorType = TrackOrderV3
  </code></pre>
  <p>Is this because <code>BaseCollectionsViewModel&lt;TrackOrderV3&gt;</code> and <code>TrackingTableViewModel</code> are invariant? Is there anyway I can resolve this problem with <code>TypeErasure</code>?</p>
  <p>If its not a protocol I could solve it as</p>
  <pre><code>class TestTableView&lt;T: BasicTrackDataExtractorProtocol, U: BaseCollectionsViewModel&lt;T&gt;&gt; {
      var viewModel: U!
  }
  
  class TestTrackingTableView: TestTableView&lt;TrackOrderV3, TrackingTableViewModel&gt; {
      func testViewModel() {
          let _ = self.viewModel.numberOfRows
      }
  }
  </code></pre>
  <p>But the issue is now I cant say <code>class TestTrackingTableView: TestTableView&lt;TrackOrderV3, TrackingTableViewModel&gt;, UITableView</code> because multiple inheritance is not allowed.</p>
  <p>P.S: Sorry for the highly confusing title, couldn't come up with a better title, will change if someone can suggest a better one :)</p>