在Swift中设置Timer

时间:2014-09-23 00:09:55

标签: swift selector nstimer

我无法让计时器在Swift中工作,请帮忙。我收到错误extra 'selector' in call

var timer = NSTimer.scheduledTimerWithTimeInterval(
   1, 
   target: self, 
   selector: Selector ("result"), 
   userInfo: nil, 
   repeats: true
)

2 个答案:

答案 0 :(得分:1)

改为使用

var timer = NSTimer.scheduledTimerWithTimeInterval    (
   1, 
    target: self, 
   selector: "result", 
   userInfo: nil, 
   repeats: true
)

答案 1 :(得分:0)

我写的方法之一:

override func viewDidLoad() {
            super.viewDidLoad()

            let aSelector : Selector = "updateTime"
            let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: aSelector, userInfo: nil, repeats: true)

        }

        func updateTime() {

        }