0
我想从NSTimer调用一个函数myTestFunction(day),天是一个int。Swift NSTimer传递变量语法
NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: #selector(ViewController.myTestFunction(_:)), userInfo: day, repeats: true)
Xcode的编译器,促使我对上述语法,但是当我把测试的FUNC它似乎并没有被调用。有任何想法吗?
我以为用户信息的主意:选择是让你变(S)/字典传递给通过的NSTimer启动的功能? –
是的,这是正确的方法,但不是像'testFunction(day)'这样的直接参数。用'timer.userInfo'获取userInfo对象。我更新了答案。 – vadian
对不起,我很厚,你的建议似乎失去了典型的NSTimer构造(例如NSTimer.scheduledTimerWithTimeInterval(0.1,..),所以没有看到我告诉它的定时器间隔或重复等。 –