每次定时器触发时,我都想在选择器函数中更新定时器的用户信息。
用户信息:
var timerDic = ["count": 0]
定时器:
Init: let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("cont_read_USB:"), userInfo: timerDic, repeats: true)
选择器功能:
public func cont_read_USB(timer: NSTimer)
{
if var count = timer.userInfo?["count"] as? Int
{
count = count + 1
timer.userInfo["count"] = count
}
}
我在最后一行收到错误:
“任何物体?” 没有名为“下标”的成员
这里有什么问题?在 Objective_C 中,此任务使用NSMutableDictionary
asuserInfo