Swift: How to assign different number values to rows in a UIPickerView?

186 views Asked by At

I have an array representing the rows of a UIPickerView:

var exerciseArray = ["Sitting","Walking","Bowling","Biking Slow","Biking Fast","Golf","SoftBall","BaseBall","Weight Training","Ice Skating","Tennis","Basketball","Jogging","Swimming","Soccer","Jump Rope"]

How can I assign different number values to each of the different rows in var exerciseArray so I can access these assigned numbers later on for calculations?

I am new to programming, so please provide as much code as possible. Thank you!

1

There are 1 answers

1
Nick Hawkes On
struct Model {
    var name: String
    var number: Int 
    }

var exersise : [Model] = []

var Position1 = Model(name: "Sitting", number: 100)  
var Position2 = Model(name: "Walking", number: 130)  
var Position3 = Model(name: "Bowling", number: 160)  
var Position4 = Model(name: "Biking", number: 200)  
var Position5 = Model(name: "Golf", number: 300)

exersise = [Position1,Position2,Position3,Position4,Position5]


println(exersise[0].name)  
println(exersise[0].number)



for var index = 0; index < exersise.count; index++ {
    println("Name = \(exersise[index].name) and has the number = \(exersise[index].number)")  
}