如何像在 obj-c 中那样在 Swift 中设置目标(调用类级函数):
call a class level method in scheduledTimerWithTimeInterval
最佳答案
class MyClass: NSObject{
class func startTimer(){
NSTimer.scheduledTimerWithTimeInterval(2.0, target: MyClass.self, selector: "callByTimer:", userInfo: nil, repeats: true)
}
class func callByTimer(timer: NSTimer!){
println("Called")
}
}
MyClass.startTimer()
关于swift - NSTimer scheduleTimerWithTimeInterval 和目标是 "class level function",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25970842/