I have an API that takes a parameter called "take". In viewDidLoad, I am passing 10 and I got 10 data and append them into my array of objects. I use scrollViewDidEndDragging method for pagination like below. I increase my takeCount by ten by and called my API again and append them to my existing array. Problem is that the 1. object and 11. The object is the same when I scroll to the bottom. Should I remove old data but isn't it against the logic of pagination?
Pagination Code
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if scrollView.contentOffset.y > scrollView.contentSize.height - scrollView.frame.size.height{
self.takeCount += 10
if self.takeCount <= self.sampleDataCountLimit{
Service().fetchData(count: self.takeCount) { (result) in
switch result{
case .success(let cars):
//self.carModel.removeAll(keepingCapacity: false)
self.carModel.append(contentsOf: cars)
DispatchQueue.main.async {
self.tableView.reloadData()
print(self.carModel.count)
print(self.carModel)
}
case .failure(let error):
print(error.localizedDescription)
}
}
}
}
}