【发布时间】:2014-12-03 02:33:34
【问题描述】:
我在 Swift 中使用“NSTimer.scheduledTimerWithTimeInterval”的所有示例都显示使用“target: self”参数,但不幸的是,这不能直接在 Swift Playgrounds 中使用。
Playground execution failed: <EXPR>:42:13: error: use of unresolved
identifier 'self'
target: self,
这是上面引用的导致错误的示例:
func printFrom1To1000() {
for counter in 0...1000 {
var a = counter
}
}
var timer = NSTimer.scheduledTimerWithTimeInterval(0,
target: self,
selector: Selector("printFrom1To1000"),
userInfo: nil,
repeats: false
)
timer.fire()
【问题讨论】:
标签: swift nstimer swift-playground