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.
1 Answers
1
votes
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(_:))
func countdown(). - Jeffery Thomas#selectorsyntax is new to Swift 2.2 which was introduced less than a month ago. You can still use the old way, but it's deprecated. I recommend you learn Swift from the official Swift book provided by Apple instead of using YouTube videos, as it is always up to date. - Andy IbanezSelector("countdown")or what Xcode suggested. - vacawama