What I'm trying to do is to get today's weekday. From it I get the rest 6 weekdays, I put them into an array and then try to use this array to update 7 UILabels. A short list of weekdays starting from today that is. My UILabels are in a referencing outlet collection and I have set their tags from 0 to 6.
I have tried multiple different versions (originally without any array) of this and have managed to make this work on Playground, up to the point that I have the weekdays in the array but on the actual project, when I try to update the labels, it builds successfully but then crashes.
Edit: Crash comes after successful build. Error in Thread 1: breakpoint 1.1. Stops at the row super.viewDidLoad() apparently.
Edit2: made changes as suggested. Build succeeds and then crashes in the same style as in first Edit.
Any help is appreciated.
import UIKit
class ViewController: UIViewController {
@IBOutlet var label: [UILabel]!
var rollingDay = NSDate()
var array: [String] = []
func addDays() {
var calendar = NSCalendar.currentCalendar()
var formatter = NSDateFormatter()
var stringRolling = formatter.stringFromDate(rollingDay)
for var x = 0; x<7; x++ {
calendar = NSCalendar.currentCalendar()
formatter = NSDateFormatter()
formatter.dateFormat = "EEEE"
stringRolling = formatter.stringFromDate(rollingDay)
array.append(stringRolling)
rollingDay = calendar.dateByAddingUnit(.CalendarUnitDay, value: 1, toDate: rollingDay, options: nil)!
}
}
func updateLabels() {
for (index, day) in enumerate(array) {
let label : UILabel = self.view.viewWithTag(index) as! UILabel
label.text = day as String
}
}
override func viewDidLoad() {
super.viewDidLoad()
addDays()
updateLabels()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}