从异步Json数组设置pickerView

从异步Json数组设置pickerView,json,swift,swift3,Json,Swift,Swift3,我有一个函数getSemainesStages(),它读取一个远程json文件,并将结果放入一个(全局范围)数组中 问题是它是异步的,就像有人向我解释的那样,我需要这个数组来填充pickerView数据源 所以当我打电话时: func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { return lesSemaines.count } 数

我有一个函数getSemainesStages(),它读取一个远程json文件,并将结果放入一个(全局范围)数组中

问题是它是异步的,就像有人向我解释的那样,我需要这个数组来填充pickerView数据源

所以当我打电话时:

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return lesSemaines.count
    }
数组仍然为空,对于

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return lesSemaines[row]
    }

只有在我的getSemainesStages()函数为空后,我才能这样做?

在填充数组以重新加载节/行后,可以调用
UIPickerView.reloadAllComponents()

var lesSemaines: [String] {
    didSet { 
        pickerView.reloadAllComponents()
    }
}

在发布问题之前,请不要问多个问题。