Q:

Swift changing different labels labelData in every loop

So i would like to simplify this chunk of code to a simple for loop.
But UITextFields and UILabels are giving me some hard time.
    @IBOutlet var thingsIUse: UITextField!
    @IBOutlet var orThis: UILabel!

    saveProgress(year: year, season: season, day: "1", value: "\(Int(day1new.text!)! + Int(day1newExtra.text!)!)")
    saveProgress(year: year, season: season, day: "2", value: "\(Int(day2new.text!)! + Int(day2newExtra.text!)!)")
    saveProgress(year: year, season: season, day: "3", value: "\(Int(day3new.text!)! + Int(day3newExtra.text!)!)")
    saveProgress(year: year, season: season, day: "4", value: "\(Int(day4new.text!)! + Int(day4newExtra.text!)!)")
    saveProgress(year: year, season: season, day: "5", value: "\(Int(day5new.text!)! + Int(day5newExtra.text!)!)")
    saveProgress(year: year, season: season, day: "6", value: "\(Int(day6new.text!)! + Int(day6newExtra.text!)!)")
    saveProgress(year: year, season: season, day: "1Taki", value: day1new.text!)
    saveProgress(year: year, season: season, day: "2Taki", value: day2new.text!)
    saveProgress(year: year, season: season, day: "3Taki", value: day3new.text!)
    saveProgress(year: year, season: season, day: "4Taki", value: day4new.text!)
    saveProgress(year: year, season: season, day: "5Taki", value: day5new.text!)
    saveProgress(year: year, season: season, day: "6Taki", value: day6new.text!)

To something like this...
    for k in 1...10{
        saveProgress(year: year, season: season, day: "\(k)", value: "\(Int(day\(k)new.text!)! + Int(day\(k)newExtra.text!)!)")
        saveProgress(year: year, season: season, day: "\(k)Taki", value: day\(k)new.text!)
    }

Any suggestions?

A:

You can solve this a few ways.  One is to use IBOutlet collections.  In swift, you define them as such:
@IBOutlet var dayLabels: [UILabel]!

Then make sure you go in your Xib/Storyboard and add references to your labels by clicking the little "+" beside the collecting name and dragging it to the various labels.  Since this is a collection, you can drag like this to many labels just make sure you add them in the order you want them updated.
Another way to solve this, is to create the array of the labels you want updated dynamically at runtime, like this:
let labelsToUpdate: [UILabel] = [day1new,day2new,day3new,day4new,day5new,day6new]
for k in 0...5 {
    let day = "\(k+1)"
    let label = labelsToUpdate[k]
    ...
}

There are several other optimizations you could do to keep your code clean, but this will be a good start to achieve what you want.
Good luck!

