Timer in another thread in Objective - C

前端 未结 2 522
情话喂你
情话喂你 2021-02-06 04:40

I have to define method which should be invoked periodically with some time interval. I need to invoke it in another thread (NOT main thread), because this method is used to get

2条回答
  •  清歌不尽
    2021-02-06 05:17

    Use NSRunLoop and NSTimer for work

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timer) userInfo:nil repeats:NO];
    
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    

提交回复
热议问题