title: How to push data from nested array to collectionVIew in tableVIewCell
body: <p>My layout consists out of collectionviews with posters and those collectionviews are in tableviewcells
  I load my data from the internet to Array>. The first array is for the tableviewcell, the second one is for the collectionview and then there's the struct with the URL to the poster. I always get error out of index.</p>
  
  <p>I'm a newbie in iOS developing so any help would be appreciated!</p>
  
  <p>Here's my code: </p>
  
  <pre><code>struct TVShowTitle {
      var id: Int
      var posterPath: String
  }
  
  class ForYouViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  
  @IBOutlet weak var tableView: UITableView!
  
  var tvShowIds: Array&lt;Array&lt;TVShowTitle&gt;&gt; = [[TVShowTitle]]()
  var section = 0
  
  var sectionNames = ["Comedy Blockbusters", "Exciting TV", "Horror", "Popular shows", "Sci-fi", "TV Dramas", "Thrillers"]
  
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
        return sectionNames.count;
    }
  
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SectionCell", for: indexPath) as! SectionTableViewCell
  
      section = indexPath.row
  
        cell.sectionNameLabel.text = sectionNames[indexPath.row]
      cell.imageCollectionView.reloadData()
        return cell;
    }
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      getTitlesForMostOfTheSections()
  }
  
  func getTitlesForMostOfTheSections() {
      // The function loads the URLs for the posters
      self.tableView.reloadData()
  }
  
  override var preferredStatusBarStyle: UIStatusBarStyle {
      return .lightContent
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  }
  
  extension ForYouViewController: UICollectionViewDelegate, UICollectionViewDataSource {
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCell", for: indexPath) as! ImageCollectionViewCell
  
      if tvShowIds.count &lt;= section &amp;&amp; indexPath.row &lt;= tvShowIds[section].count {
               cell.imageView.sd_setImage(with: URL(string: "https://image.tmdb.org/t/p/w300" + tvShowIds[section][indexPath.row].posterPath))
          } else {
               cell.imageView.image = #imageLiteral(resourceName: "placeholder")
          }
  }
  
  func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
      return 1;
  }
  
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
        // How many shows in a section
      if section &gt; tvShowIds.count || tvShowIds.count == 0 {
          return 0
      } else {
          return tvShowIds[section].count
      }
  }
  }
  </code></pre>