Skip to content

Instantly share code, notes, and snippets.

@lnds
Last active March 31, 2016 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lnds/8915778e80302a586c7661fc720a992f to your computer and use it in GitHub Desktop.
Save lnds/8915778e80302a586c7661fc720a992f to your computer and use it in GitHub Desktop.
Consulta en paralelo en swift
var reports = [ApiResult?]()
for i in 1...cities.count {
reports.append(nil)
}
let globalQueue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)
dispatch_apply(cities.count, globalQueue) {
i in
let index = Int(i)+2 // cities start from 2
let city = cities[index]
let rep = callApi(city, apiKey:apiKey)
reports[Int(i)] = rep
}
// sort...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment