title: what is the best way to populate a picker view with JSON data in swift?
body: <p>i am building a COVID-19 app tracker on IOS. </p>
  
  <p>In order to display the data by country, I have built a pickerView that will contain all the country names.</p>
  
  <p>thanks to an HTTP cal, I have managed to get the JSON data i.e the name of each country. ideally I wish to append each value to an array that in turn will populate the pickerView.</p>
  
  <p>Is that possible ? If yes, how would I do that ? </p>
  
  <p>I am also open to other ways to do it. Here is my code : </p>
  
  <pre><code> @IBOutlet weak var confirmedCasesLabel: UILabel!
   @IBOutlet weak var deathsLabel: UILabel!
   @IBOutlet weak var recoveriesLabel: UILabel!
  
   //MARK: - Relevant variables
   private let covidUrl: String = "https://corona-api.com/countries"
   var countryArray: [String] = [String]()
  
  
   override func viewDidLoad() {
       super.viewDidLoad()
  
       // Do any additional setup after loading the view.
       countryPickerView.delegate = self
       countryPickerView.dataSource = self
  
       //
       httpCall()
   }
  
  
   /*
   // MARK: - Navigation
  
   // In a storyboard-based application, you will often want to do a little preparation before navigation
   override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
       // Get the new view controller using segue.destination.
       // Pass the selected object to the new view controller.
   }
   */
  
   //MARK: - Functions that handles picker view delegates and data source
   func numberOfComponents(in pickerView: UIPickerView) -&gt; Int {
          return 1
      }
  
   func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -&gt; Int {
       return countryArray.count
      }
  
   func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -&gt; String? {
       return countryArray[row]
   }
  
   //MARK: - HTTP CALL - GET COUNTRY DATA
   func httpCall() {
       request(covidUrl, method: .get).responseJSON { (response) in
           if response.result.isSuccess {
               //test just print some data
               let dataJSON: JSON = JSON(response.result.value)
               //print(dataJSON)
               //on va identifier chaque pays + l'ajouter au tableau des pays
  //                let countryNameJSON = dataJSON["data"][99]["name"]
  //                print(countryNameJSON)
               for country in 0...99 {
                   let countryNameJSON = dataJSON["data"][country]["name"].stringValue
                   print(countryNameJSON)
                   //on ajoute ce nom au tabeleau de pays
                   //self.countryArray.append(countryNameJSON)
               }
  
           }
       }
   }
  
  
  
  }
  </code></pre>