title: Making multiple CollectionViews programmatically
body: <p>I am having some trouble getting two collection views, side by side in one ViewController.</p>
  
  <p>My issue is NOT with building or displaying the collection views.  Individually, I can get both on the screen as I want them, just not at the same time.</p>
  
  <p>I have debugged my code and found it falls over when setting the ‘cellForItemAt’</p>
  
  <p>I’ve also searched the forums and understand that I need to have an if statement to say…</p>
  
  <p>if collectionView == 1, then dequeue cell A, else dequeue cell B</p>
  
  <p>Unfortunately, when I go to write my if statement, xCode doesn’t find my collection views, i.e. won’t auto find them so I can compile.  Also, I get an ‘unresolved identifier’ for my cell.</p>
  
  <p>Given my efforts above, I have hit a wall and was wondering if anyone could shed some light on my issue?  Thanks</p>
  
  <p><strong>viewDidLoad code</strong></p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
  
      navigationController?.isNavigationBarHidden = false
  
      setupCollectionView()   
  }
  </code></pre>
  
  <p><strong>collectionView creation code</strong></p>
  
  <pre><code>func setupCollectionView() {
  
      let listLayout = UICollectionViewFlowLayout()
      listLayout.itemSize = CGSize(width: 300, height: 40)
      listLayout.minimumLineSpacing = 5
      listLayout.sectionHeadersPinToVisibleBounds = true
      let listFrame = CGRect(x: 0, y: 64, width: 325, height: 500)
      let listView = UICollectionView(frame: listFrame, collectionViewLayout: listLayout)
  
      // cell
      listView.register(cellA.self, forCellWithReuseIdentifier: cellAId)
  
      // header
      listView.register(headerCellA.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: headerAID)
  
      listView.delegate = self
      listView.dataSource = self
      listView.backgroundColor = .cyan
  
      self.view.addSubview(listView)
  
      let detailLayout = UICollectionViewFlowLayout()
      detailLayout.itemSize = CGSize(width: 300, height: 40)
      detailLayout.minimumLineSpacing = 5
      detailLayout.sectionHeadersPinToVisibleBounds = true
      let detailFrame = CGRect(x: 330, y: 64, width: 500, height: 650)
      let detailView = UICollectionView(frame: detailFrame, collectionViewLayout: detailLayout)
  
      // cell
      detailView.register(cellB.self, forCellWithReuseIdentifier: cellBID)
  
      // header
      detailView.register(headerCellB.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: headerBID)
  
      detailView.delegate = self
      detailView.dataSource = self
      detailView.backgroundColor = .white
  
      self.view.addSubview(detailView)
  }
  </code></pre>
  
  <p><strong>cellForItemAt code - can’t get my if statement to work</strong></p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
  if collectionView == detailView {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellAID, for: indexPath) as! ListCell
  } else {  
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellBID, for: indexPath) as! DetailCell
      }
      return cell
  }
  </code></pre>