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. DKPaginationGenerator retrieves 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

    startPage

    An integer specifying which page to begin paginating from

  • Get the next page of results as outlined in the next closure.

    Declaration

    Swift

    public func getNext() -> CancellablePromise<[T]>
  • Cancel the current pagination request, if one exists, then reset pagination back to the original startPage

    Declaration

    Swift

    public func reset()

Infinite scroll utilities

  • Trigger utility to determine if a user scrolled to the end of a UICollectionView. We recommend using this function in your UICollectionViewDelegate collectionView(_:willDisplay:forItemAt:) method to determine if you should call your getNext() promise.

    Declaration

    Swift

    func shouldGetNextPage(at indexPath: IndexPath, for collectionView: UICollectionView) -> Bool

    Parameters

    indexPath

    The indexPath at which to check if pagination should be triggered

    collectionView

    The 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 your UITableViewDelegate tableView(_:willDisplay:forRowAt:) method to determine if you should call your getNext() promise.

    Declaration

    Swift

    func shouldGetNextPage(at indexPath: IndexPath, for tableView: UITableView) -> Bool

    Parameters

    indexPath

    The indexPath at which to check if pagination should be triggered

    tableView

    The 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 your UICollectionViewDelegate collectionView(_:willDisplay:forRepresentedObjectAt:) method to determine if you should call your getNext() promise.