title: CollectionView Compositional Layout with Multiple Data Types
body: <p>I was playing around with Compositional Layouts with Diffable DataSource and so far loving it. But all of my endeavors have included a single type of Data Item.</p>
  <p>What I'm trying to achieve is have two different types of List, say <code>Car</code> and <code>Airplane</code></p>
  <p>So far what I've done is created the layouts, created an <code>Enum</code></p>
  <pre><code>enum DataItem: Hashable{
      case cars(Car)
      case airplane(Airplane)
  }
  </code></pre>
  <p>And <code>dataSource</code> initialization:</p>
  <pre><code>func configureDataSource(){
      dataSource = UICollectionViewDiffableDataSource
      &lt;Section, DataItem&gt;(collectionView: collectionView) {
          (collectionView: UICollectionView, indexPath: IndexPath, dataItem: DataItem) -&gt; UICollectionViewCell in
          
          switch dataItem {
          case .cars(let car):
              guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CarCell.reuseIdentifier, for: indexPath) as? CarCell else {fatalError(&quot;Couldn't Create New Cell&quot;)}
              ....
              return cell
          case .airplanes(let airplane):
              guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: AirplaneCell.reuseIdentifier, for: indexPath) as? AirplaneCell else {
                  fatalError(&quot;Couldn't Create New Cell&quot;)
              }
              ....
              return cell
          }
      }
      dataSource.apply(snapshotForCurrentState(), animatingDifferences: false)
  }
  </code></pre>
  <p>Now the part that I'm stuck is creating the snapshot.</p>
  <p>Ideally what I'd like to do is</p>
  <pre><code>func snapshotForCurrentState() -&gt; NSDiffableDataSourceSnapshot&lt;Section, DataItem&gt;{
      var snapshot = NSDiffableDataSourceSnapshot&lt;Section, DataItem&gt;()
      snapshot.appendSections(Section.allCases)
      snapshot.appendItems([cars], toSection: Section.cars)
      snapshot.appendItems([airplanes], toSection: Section.airplanes)
      return snapshot
  }
  </code></pre>
  <p>What am I missing here?</p>