Skip to content

Instantly share code, notes, and snippets.

@christ776
Created August 4, 2016 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christ776/47250936fa02a58373c3e220bad49ae0 to your computer and use it in GitHub Desktop.
Save christ776/47250936fa02a58373c3e220bad49ae0 to your computer and use it in GitHub Desktop.
override func scrollViewDidScroll(scrollView: UIScrollView) {
// when reaching bottom, load a new page
if scrollView.contentOffset.y == scrollView.contentSize.height - scrollView.bounds.size.height
{
// fetch next page of results
//self.footerActivityIndicator.startAnimating()
self.dataPaginator.fetchNextBatch()
}
}
private final class Paginator {
var offset:Int = 0
var challengeId : String!
var responseHandler:([Image] throws -> ())!
func fetchNextBatch() {
Store.instance.getImages(fromChallenge: challengeId,offset: String(offset)).onComplete { (result) in
switch result {
case .Success(let images):
if !images.isEmpty {
self.offset += 10
_ = try? self.responseHandler(images)
self.fetchNextBatch()
}
default:
break
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment