jack paster jack paster - 7 months ago 42
Swift Question

How can I flip the data array for a picker

I have an array for a picker that shows only years, but I want the array to go from 2016 and work its way down. Instead it works it's way up from 1900 to 2016. How can I flip it. Here is a picture of what I'm talking about and the code.

let CountryData = Array(1900...2015)
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return CountryData.count

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
YearBuilt.text = String(describing: CountryData[row])

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

Picture of what I'm talking about


How about:

let CountryData = Array((1900...2015).reversed())