I want to load two NSURLSession. The problem is that in the second NSURLSession I need a key which is given by the first NSURLSession.
This is what I did but it doesn't seem working !
NSURLSession.sharedSession().dataTaskWithURL(url!) { (data, response, error) in
do {
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers)
// fetching items from json ...
for item in items {
// I extract an ID from each item
let myID = item["id"] as! String
/* Here is the problem I want to call another NSURLSession with
a url that contains this myID (String) */
let url2 = NSURL(string:"http://example.com/something?ID=\(myID)")
NSURLSession.sharedSession().dataTaskWithURL(url2!) { (data2, response2, error2) in
do {
//The problem is that this code is not executed in each for loop !
} catch let jsonError2 {
print(jsonError2)
}
}.resume()
}
} catch let jsonError {
print(jsonError)
}
}.resume()
What should I do?
For those who are interested, the solution was to keep this code and to add a function that sort the data in the array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With