-2

I am using https://github.com/mxcl/PromiseKit for setting up the promosekit for chaining the API calls.

I have query regarding the how to implement paging in promisekit.

darshan
  • 1,115
  • 1
  • 14
  • 29
  • and whats your question? – Emre Önder May 07 '18 at 10:43
  • I am having problem in implementing paging in promise kit where it we are passing page 1 as parameter then it's return date and chaining 2nd page untill all page had been fetched – darshan May 07 '18 at 11:00
  • Can you please update your question with this detail and some code please. You can't get answer without being clear and giving detail. – Emre Önder May 07 '18 at 11:01
  • What you're looking for is this: https://stackoverflow.com/questions/38404047/promsiekit-alamofire-for-loading-paged-http-data – strangetimes Oct 02 '20 at 12:48

1 Answers1

0

Instead of using PromiseKit, use OperationQueue. Instead of magic you will understand every bit of it.

Obviously it will took more code than PromiseKit but It's provided built in Apple SDK.

Please check the following snippet

// setup your operation queue
// typically done where you start sending the api request
// like viewDidLoad
// assumed that opQueue is declared as class's instance member
opQueue = OperationQueue.init()
opQueue.maxConcurrentOperationCount = 1 // ensure that only one operation will run at a time
opQueue.name = "Api Call Serializer"
opQueue.qualityOfService = QualityOfService.background

// after instantiating add a operation to the queue
opQueue.addOperation {
    makeApiCall(url: first_url)
}


func makeApiCall(url: URL) {
    //put your api call code here
    YOUR_API_CALL({(responseData)// i have assumed that your api call will ending in a swift closure. If you use delegate, it will be same as following.
        // your processing of api response
        // build the next_url for pagination.
        opQueue.addOperation {
            makeApiCall(url: next_url)
        }            
    })
}

Hope it helps.

Ratul Sharker
  • 7,484
  • 4
  • 35
  • 44
  • @darshan consider leaving a comment, if you face any issue with this approach. – Ratul Sharker May 08 '18 at 16:59
  • Although the post is useful, I don't think it's revenant nor does it answer the question. It also does not help to suggest that the OP replace PromiseKit with OperationQueue. There are (many) reasons why one would want to use PromiseKit (and you've mentioned one of them yourself). The question, although poorly put, was about loading pagenized data from an API that expects a `start ` and `limit` of some sort. A solution is posted here: https://stackoverflow.com/questions/38404047/promsiekit-alamofire-for-loading-paged-http-data – strangetimes Oct 02 '20 at 12:52