How to get the first bit of an array item with multiple properties?

I have an array:

Code Block
var myHorses = [
    Horse(name: "Donnerhall", idNumber: 1, gender: "Stallion"),
Horse(name: "Mischa", idNumber: 2, gender: "Mare")]

I want to make a picker view with only the names from the array showing. I have previously used button.tag in another VC to find the horseIndex. Is there a way to list only the names in the picker view?

Code Block
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return myHorses[row]
        //pasted from another VC, maybe something like this can work here
var horseName = for horseIndex in myHorses.indices {
        let horse = myHorses[horseIndex]
        button.tag = horseIndex
    }


Thanks in advance!
Answered by OOPer in 642707022

Is there a way to list only the names in the picker view?

Return the name of the Horse.

Code Block
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
let theHorse = myHorses[row]
return theHorse.name
}


Accepted Answer

Is there a way to list only the names in the picker view?

Return the name of the Horse.

Code Block
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
let theHorse = myHorses[row]
return theHorse.name
}


That worked perfectly, thanks :)
How to get the first bit of an array item with multiple properties?
 
 
Q