Last active
March 31, 2016 14:35
-
-
Save lnds/8915778e80302a586c7661fc720a992f to your computer and use it in GitHub Desktop.
Consulta en paralelo en swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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