Skip to content

Instantly share code, notes, and snippets.

@salmaanahmed
Created April 18, 2019 12:41
Show Gist options
  • Save salmaanahmed/23d5d874ef432192039d7ae58087b59c to your computer and use it in GitHub Desktop.
Save salmaanahmed/23d5d874ef432192039d7ae58087b59c to your computer and use it in GitHub Desktop.
func loadMore(_ pageNumber: Int, _ pageSize: Int, onSuccess: ((Bool) -> Void)?, onError: ((Error) -> Void)?) {
// Call your api here
// Send true in onSuccess in case new data exists, sending false will disable pagination
// If page number is first, reset the list
if pageNumber == 1 { self.list = [Model]() }
// else append the data to list
self.list.append(apiResponseList)
// If Api responds with error
onError?(apiError)
// Else end success with flag true if more data available
let moreDataAvailable = !apiResponseList.isEmpty
onSuccess?(moreDataAvailable)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment