title: Infinite scroll tableView, swift
body: <p>With some research I found this method quiete usefull to reach my purpose: pagination in a table view.</p>
  <p>What I do is:</p>
  <pre><code>func scrollViewDidScroll(_ scrollView: UIScrollView) {
      let offsetY = scrollView.contentOffset.y
      let contentHeight = scrollView.contentSize.height
      
      if offsetY &gt; contentHeight - scrollView.frame.height {
  
          //print
  
          if vievModel.!paginationFinished {
              self.viewModel.loadMoreData()
              self.tableView.reloadData()
          }
      }
  }
  </code></pre>
  <p>The variable paginationFinished is manage in my viewModel, and when I call load more Data the page number is increasde by 1.</p>
  <p>The problem is that this piece of code, when I scroll down to load more data, calls my viewModel function like all the possible times.</p>
  <p>In fact if I print something in the line of my code it's printed like 15 times when i reach the end of my page.</p>
  <p>What is the problem with this code? How can I improve this? I would like to reach the end of the page and call my <strong>loadMoreData</strong> once, so it loads the data in the pageCounter. I think i'm missing something</p>