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