In my app I have a task in which user will enter the from and to date and the url will fetch the data. Each URL will return large sized JSON
string from the server.
Problem arises when user enters larger date interval which makes the server to hang. In android version of the app I used AsyncTask
to done this. In that I split the requests in to multiple if user enters large date interval. I use for loop to fetch data for each day and publish the progress in onProgressUpdate
after each day task completed.
In swift also I need to use multiple data tasks in a for loop and publish the results.
for i in 0 ..< dates.count {
// Getting response from server //
let response = getResponse(imei: sImei, date: dates[i])
parseResponse(response)
}
This is how I planned on doing this. But don't know how to implement this.
I saw some suggestions to use DispatchGroup
. I'm not familiar with that. So please guide me to achieve my task.
Note: Giving large date interval in single dataTask will choke my server. Because, it's a low end server. So I have to query data for individual dates and combine them.
Use Recursion: initially i = 0 .