Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTimer scheduledTimerWithTimeInterval and target is "class level function"

Tags:

swift

How to set target in Swift (to call a class level function) the way it is done in obj-c:

call a class level method in scheduledTimerWithTimeInterval

like image 848
sabiland Avatar asked May 01 '26 13:05

sabiland


1 Answers

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()
like image 50
Sandeep Avatar answered May 04 '26 20:05

Sandeep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!