我正在尝试使用an NSURLSession在for循环中加载多个请求.
for id in ids{
// ids is an Array of String
let url = NSURL(string:"http://example.com/something?ID=\(id)")
// ^
NSURLSession.sharedSession().dataTaskWithURL(url!){(data, response, error)in
if error2 != nil {
print(error2)
return
}
do{
let strjson = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers)
// Here is the problem the for loop doesn't let enough time to the NSURLSession
}catch let errorjson {
print(errorjson)
}
}.resume
}
Run Code Online (Sandbox Code Playgroud)