我正在尝试创建一个for循环,它会在每次迭代后将数据附加到数组中。我得到" []" (nil)作为我尝试打印数组时的响应。这是我的代码:
class func fetchChartPoints(days: Int, base: String, target: String, completion:@escaping (_ chartPoints: [Double]) -> ()) {
let datesArray = formatDate(days: days)
var array = [Double]()
for date in datesArray {
Alamofire.request("http://api.fixer.io/\(date)?base=\(base)").responseJSON { response in
//print(response)
if let resultJSON = response.result.value as? [String : AnyObject] {
let rates = resultJSON["rates"] as? [String: Double]
array.append((rates?[target])!)
}
}
}
completion(array)
print(array)
}