I'd like to know how to use an NSTimer
inside a Swift Playground. This question has been asked before, but none of the answers actually answered the question.
Here's my Playground code:
import Foundation
class MyClass {
func startTimer() {
NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "onTimer:", userInfo: nil, repeats: true)
}
func onTimer(timer:NSTimer!) {
println("Timer here")
}
}
var anInstance = MyClass()
anInstance.startTimer()
Instantiating NSTimer
with scheduledTimerWithTimeInterval
creates the timer and schedules it on the current run loop.
But the method onTimer
is never called. Why?