[DataHolder]: Fixes for out-of-bounds condition and revert back to if-else instead of guard-else for better representation of logic

This commit is contained in:
Magesh K
2025-01-12 00:03:25 +05:30
parent d13e469cf2
commit 61989e7d40
2 changed files with 36 additions and 40 deletions

View File

@@ -77,7 +77,13 @@ public class PaginationDataHolder {
let count = UInt(items.count)
if(count == 0) { return items }
// since we operate on any input items list at any time,
// we set currentPageIndex as last availablePage if out of bounds
let availablePages = UInt(ceil(Double(count) / Double(itemsPerPage)))
self.currentPageindex = min(availablePages-1, currentPageindex)
let startIndex = currentPageindex * itemsPerPage
let estimatedEndIndex = startIndex + (itemsPerPage-1)
let endIndex: UInt = min(count-1, estimatedEndIndex)