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!
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

Simen Anthonsen
1,097 PointsTimer not working
var timerCount = 0
var timerRunning = false
var timer = NSTimer()
@IBOutlet weak var timerLabel: UILabel!
func counting () {
timerCount += 1
timerLabel.text = "\(timerCount)"
}
@IBAction func startButton(sender: AnyObject) {
timer = NSTimer(timeInterval: 1, target: self, selector: ("counting"), userInfo: nil, repeats: true)
}
What is wrong with my code?
1 Answer

Jhoan Arango
14,575 PointsHello:
Try this
var timerCount = 0
var timerRunning = false
var timer = NSTimer()
@IBOutlet weak var timerLabel: UILabel!
@IBAction func startButton(sender: AnyObject) {
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "counting:", userInfo: nil, repeats: true)
}
func counting () {
timerCount++
timerLabel.text = "\(timerCount)"
}
}
I modified your code a bit.
Good luck.