How do I create a NSTimer on a background thread?

前端 未结 10 638
感情败类
感情败类 2020-11-28 02:04

I have a task that needs to be performed every 1 second. Currently I have an NSTimer firing repeatedly every 1 sec. How do I have the timer fire in a background thread (no

10条回答
  •  自闭症患者
    2020-11-28 02:52

    class BgLoop:Operation{
        func main(){
            while (!isCancelled) {
                sample();
                Thread.sleep(forTimeInterval: 1);
            }
        }
    }
    

提交回复
热议问题