- Store
nextPage
andtotal
- Only fetch in the last cell if
dataSource.count < paging.total
- Only assign nextPage if
resp.data
is not empty
Last active
April 2, 2021 01:17
-
-
Save muizidn/e3ad553c7718bd88cad9bb44b11fb786 to your computer and use it in GitHub Desktop.
Paging Easy Swift
This file contains hidden or 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
if indexPath.row == dataSource.count - 1 && dataSource.count < paging.total { | |
self.fetchPaging() | |
} |
This file contains hidden or 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
Api.fetch(page: paging.nextPage) { [weak self]res in | |
switch res { | |
case .success(let resp): | |
if !resp.data.isEmpty { | |
self?.paging.nextPage += 1 | |
} | |
self?.paging.total = resp.total | |
case .failure(let err): | |
print("ERROR: \(err)") | |
} | |
} |
This file contains hidden or 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
var paging: (nextPage: Int, total: Int) = (1,0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment