Using an NSTimer in Swift

前端 未结 10 1513
生来不讨喜
生来不讨喜 2020-12-05 06:19

In this scenario, timerFunc() is never called. What am I missing?

class AppDelegate: NSObject, NSApplicationDelegate {

    var myTimer: NSTimer? = nil

             


        
10条回答
  •  -上瘾入骨i
    2020-12-05 06:55

    NSTimer's are not scheduled automatically unless you use NSTimer.scheduledTimerWithTimeInterval:

    myTimer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "timerFunc", userInfo: nil, repeats: true)
    

提交回复
热议问题