Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Konrad Pilch
2,435 PointsChanging your label's displayed text after every 5s
l want to look through mt array and change the field of my question label after every five seconds. l got the below code but can't seem to figure it out. Any ideas please
import UIKit
class ViewController: UIViewController {
var timer = NSTimer()
var time = 0
@IBOutlet var question: UILabel!
var arrayOfStrings: [String] = ["We are what we say we are", "who is the first president of the United states", "Swift is an awesome language"]
@IBOutlet var timerLabel: UILabel!
func increaseTimer(){
time++
timerLabel.text = "\(time)"
}
@IBAction func play(sender: AnyObject) {
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("increaseTimer"), userInfo: nil, repeats: true)
}
@IBAction func reset(sender: AnyObject) {
timer.invalidate()
time = 0
timerLabel.text = "0"
}
@IBAction func pause(sender: AnyObject) {
timer.invalidate()
}
override func viewDidLoad() {
super.viewDidLoad()
// 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.
}
}
So in 5s l would have "We are what we say we are". In 10s I would have "who is the first president of the United states" and in 15s l would have "Swift is an awesome language" . Any suggestions would be greatly appreciated.