DKPagingGenerator
public class DKPagingGenerator<T>
Use this class to load consecutive “pages” of content from a listable API endpoint. Includes utilities to check for new content while scrolling in a UICollectionView, UITableView, NSCollectionView, or NSTableView.
-
Required - Set this closure to process a single page of results, and return your request packaged in a CancellablePromiseKit promise. A single page is requested and returned in the promise format. By calling
getNext(), this closure will be used.Declaration
Swift
public var next: ((_ page: Int) -> CancellablePromise<[T]>)! -
The current page
Declaration
Swift
public var page: Int -
The number of items in a single page request. This integer is used to calculate when a list endpoint reaches the end.
Declaration
Swift
public var pageSize: Int -
Test if pagination loaded all objects from the list.
Declaration
Swift
public var didReachEnd: Bool -
Test if pagination is in the process of retrieving a page.
Declaration
Swift
public var isFetchingPage: Bool { get } -
Initialize a pagination object, beginning with the specified
startPage.DKPaginationGeneratorretrieves items of a generic Type, so a placeholder Type is required to specify what kinds of objects will be paginated and returned.Declaration
Swift
public init(startPage: Int)Parameters
startPageAn integer specifying which page to begin paginating from
-
Get the next page of results as outlined in the
nextclosure.Declaration
Swift
public func getNext() -> CancellablePromise<[T]> -
Cancel the current pagination request, if one exists, then reset pagination back to the original
startPageDeclaration
Swift
public func reset()
-
Trigger utility to determine if a user scrolled to the end of a
UICollectionView. We recommend using this function in yourUICollectionViewDelegatecollectionView(_:willDisplay:forItemAt:)method to determine if you should call yourgetNext()promise.Declaration
Swift
func shouldGetNextPage(at indexPath: IndexPath, for collectionView: UICollectionView) -> BoolParameters
indexPathThe indexPath at which to check if pagination should be triggered
collectionViewThe UICollectionView to check for pagination
-
Trigger utility to determine if a user scrolled to the end of a
UITableView. We recommend using this function in yourUITableViewDelegatetableView(_:willDisplay:forRowAt:)method to determine if you should call yourgetNext()promise.Declaration
Swift
func shouldGetNextPage(at indexPath: IndexPath, for tableView: UITableView) -> BoolParameters
indexPathThe indexPath at which to check if pagination should be triggered
tableViewThe UITableView to check for pagination
-
Trigger utility to determine if a user scrolled to the end of a
NSCollectionView. We recommend using this function in yourUICollectionViewDelegatecollectionView(_:willDisplay:forRepresentedObjectAt:)method to determine if you should call yourgetNext()promise.
View on GitHub
Install in Dash
DKPagingGenerator Class Reference