title: Swift 4 UICollectionView detect end of scrolling
body: <p>I have an <code>Horizontal</code> <code>UICollectionView</code> on my app and I want to load more data when the user reaches the end (or nearly to the end) of UICollectionView while dragging on the left.</p>
  
  <p>I'm using Swift 4. I found some Swift 3 solutions but they do not work for me.</p>
  
  <p>My current code is:</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return self.videoViewModel.images.count
  }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CollectionViewCell
      cell.imgImage.image = self.videoViewModel.images[indexPath.row]
  
      return cell
  }
  
  func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
      updateVideo(data: self.videoViewModel.relatedVideos[indexPath.row])
  }
  </code></pre>