这是我正在尝试做的一些示例代码。
func firstFunction() {
var timer = NSTimer.scheduledTimerWithTimeInterval(0.6, target: self, selector: Selector("secondFunction:"), userInfo: self.data!.getInfo(), repeats: false);
println("Info: \(timer.userInfo)");
}
func secondFunction(value: Int) {
println("Called with \(value)");
}
以下是输出:
Info: Optional((
2
))
和Called with 140552985344960
用############ 调用也是不断变化的。即使我只使用一个数字代替self.data!.getInfo
我仍然得到Info: Optional(2)
作为输出,并且 Called with output 仍然会发生变化。我认为它正在发生,因为传递的值是可选的,那么如果这是问题,我该如何让它不是可选的呢?