Seth Daetwiler
Seth Daetwiler

Reputation: 1

NSTimer Confusion

I'm trying to have a label subtract every second (a countdown of sorts) and when I make a variable "timer" and set it to NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "countdown", userInfo: nil, repeats: true) it won't work. The countdown function that I'm trying to call subtracts from the label but when I try to put the "countdown" in the selector it says to replace it with #selector(Hard.countdown). All the tutorials on YouTube are different so I do not know what to do. Your help will be greatly appreciated.

Upvotes: 0

Views: 147

Answers (1)

J.Wang
J.Wang

Reputation: 1236

Swift 2.2 added the new #selector syntax for safer selector. (We use pure string before). For NSTimer, you'll need to have a countdown method like the following:

func countdown(timer: NSTimer)

Don't forget the parameter, otherwise it won't work. And reference it as a selector like this: #selector(Hard.countdown(_:))

Upvotes: 1

Related Questions