With some research I found this method quiete usefull to reach my purpose: pagination in a table view.

What I do is:

```
func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let offsetY = scrollView.contentOffset.y
    let contentHeight = scrollView.contentSize.height

    if offsetY > contentHeight - scrollView.frame.height {

        //print

        if vievModel.!paginationFinished {
            self.viewModel.loadMoreData()
            self.tableView.reloadData()
        }
    }
}

```

The variable paginationFinished is manage in my viewModel, and when I call load more Data the page number is increasde by 1.

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.

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.

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 **loadMoreData** once, so it loads the data in the pageCounter. I think i'm missing something