【发布时间】:2014-12-17 03:24:16
【问题描述】:
这是我正在尝试做的一些示例代码。
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 输出仍然会发生变化。我认为它正在发生,因为传递的值是可选的,那么如果这是问题,我该如何使它不是可选的呢?
【问题讨论】:
-
secondFunction 应该有一个 NSTimer 作为它的参数,如果你想获取定时器的用户信息...
-
我尝试使用 NSDictionary 来存储数据,但没有任何区别。我见过其他例子,其中 userInfo 能够将单个参数作为对象。
标签: ios swift selector nstimer userinfo