@selector() in Swift?

后端 未结 23 2436
清酒与你
清酒与你 2020-11-21 15:24

I\'m trying to create an NSTimer in Swift but I\'m having some trouble.

NSTimer(timeInterval: 1, target: self, selector: test(), us         


        
23条回答
  •  南笙
    南笙 (楼主)
    2020-11-21 16:09

    For Swift 3

    //Sample code to create timer

    Timer.scheduledTimer(timeInterval: 1, target: self, selector: (#selector(updateTimer)), userInfo: nil, repeats: true)
    
    WHERE
    timeInterval:- Interval in which timer should fire like 1s, 10s, 100s etc. [Its value is in secs]
    target:- function which pointed to class. So here I am pointing to current class.
    selector:- function that will execute when timer fires.
    
    func updateTimer(){
        //Implemetation 
    } 
    
    repeats:- true/false specifies that timer should call again n again.
    

提交回复
热议问题