【发布时间】:2015-08-21 12:34:52
【问题描述】:
我做了一个“命令行工具”,我需要使用 NSTimer。 我启动了计时器,但它不起作用...
import Foundation
class ct : NSObject {
func start() {
var timer = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: Selector("update"), userInfo: nil, repeats: true)
}
func update() {
println("test timer");
}
}
var a = ct();
a.start()
while(true) { sleep(10000000) }
【问题讨论】:
-
尝试让计时器成为类的成员。
-
你能举个例子吗?
-
var timer : NSTimer?上面的启动函数然后在启动函数中这样做 time = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: Selector("update"), userInfo: nil, repeats: true),如果不工作尝试将其添加到当前运行循环