NSTimer scheduledTimerWithTimeInterval和target是“类级别函数”

时间:2014-09-22 09:35:09

标签: swift

如何在Swift中设置 target (调用类级别函数),方法是在obj-c中完成:

call a class level method in scheduledTimerWithTimeInterval

1 个答案:

答案 0 :(得分:12)

class MyClass: NSObject{

  class func startTimer(){
    NSTimer.scheduledTimerWithTimeInterval(2.0, target: MyClass.self, selector: "callByTimer:", userInfo: nil, repeats: true)

  }

  class func callByTimer(timer: NSTimer!){
    println("Called")
  }

}

MyClass.startTimer()