Created
August 4, 2016 15:00
-
-
Save christ776/47250936fa02a58373c3e220bad49ae0 to your computer and use it in GitHub Desktop.
This file contains 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
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