Created
April 18, 2019 12:41
-
-
Save salmaanahmed/23d5d874ef432192039d7ae58087b59c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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