- I’ve got 20 labels.
- They’ll get assigned values to display via a loop in a function
- I’m trying not to write 20 full statements of LABEL1.TEXT = “blah blah”, LABEL2.TEXT = “blah”, and so on.
I’ve got 20 labels here:
var round1 : UILabel!
var round2 : UILabel!
(and so on)
I’ve made a string array of all the label names:
ex: labelNameArray = [“round1”, “round2”, “round3”…“round20”]
I have an array of all the values to be shown on the labels.
ex: valuesForLabels = [100, 200, 300, … 2000]
Is there a way to “swiftly” do this:==> round1.text = valuesForLabels
by doing something like this?:===> labelNameArray.text = valuesForLabels
That way I can run the iteration in a loop and avoid writing a function with 20 full statements giving value to label.text.
I’ve tried making an array of UILabels but I can’t get them populated with anything, and I keep running across "cannot assign value of String to subscript type UILabel. So, it begs the question of what CAN you pass into an array of UILabels?
I know I’m circling the solution—syntactically I’m missing something.