title: How to implement nested collection views?
body: <p>I am following this famous <a href="https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell-in-swift/" rel="nofollow noreferrer">tutorial</a>
  and would like to instead implement a collectionView inside of another collectionView. I think I almost have it with this in my ViewController.swift: </p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController, UICollectionViewDelegate,UICollectionViewDataSource {
      let model: [[UIColor]] = generateRandomData()
  
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return model.count
      }
  
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "outerCell", for: indexPath) as! OuterCollectionViewCell
          return cell
      }
  
      func collectionView(_ collectionView: UICollectionView,
                          willDisplay cell: UICollectionViewCell,
                          forItemAt indexPath: IndexPath){
          guard let outerCollectionViewCell = cell as? OuterCollectionViewCell else { return }
          outerCollectionViewCell.setCollectionViewDataSourceDelegate(dataSourceDelegate: self, forRow: indexPath.row)
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view, typically from a nib.
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
  
  }
  
  extension ViewController: UICollectionViewDelegate, UICollectionViewDataSource {
      func collectionView(collectionView: UICollectionView,
                          numberOfItemsInSection section: Int) -&gt; Int {
  
          return model[collectionView.tag].count
      }
  
      func collectionView(collectionView: UICollectionView,
                          cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
  
          let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell",
                                                                           forIndexPath: indexPath)
  
          cell.backgroundColor = model[collectionView.tag][indexPath.item]
  
          return cell
      }
  }
  </code></pre>
  
  <p>Then: </p>
  
  <pre><code>class OuterCollectionViewCell: UICollectionViewCell {
      @IBOutlet weak var innerCollectionView: UICollectionView!
  
      func setCollectionViewDataSourceDelegate
          &lt;D: UICollectionViewDataSource &amp; UICollectionViewDelegate&gt;
          (dataSourceDelegate: D, forRow row: Int) {
  
          innerCollectionView.delegate = dataSourceDelegate
          innerCollectionView.dataSource = dataSourceDelegate
          innerCollectionView.tag = row
          innerCollectionView.reloadData()
      }
  }
  </code></pre>
  
  <p>However Xcode is angry: Redundant conformance of <code>ViewController</code> to protocol <code>UICollectionViewDataSource</code> and <code>UICollectionViewDelegate</code>. This is understandable as I am defining it twice.. </p>
  
  <p>How do I specify the difference between delegate methods for the inner and outer collectionViews here? </p>