Search code examples
iosmultithreadingnstimer

iOS: How to create a Timer in an extra Thread


I want to create a timer within an extra thread of my application. I am very new to cocoa touch so I appreciate all good explanations.


Solution

  • You may use a timer update function like this:

     NSTimer _countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f
                                                       target:self
                                                     selector:@selector(countDownUpdate)
                                                     userInfo:nil
                                                      repeats:YES];
    

    FYI: This doesn't ensure that this "countDownUpdate" is called every second exactly, but the idea is that you check the real time inside this method. You may look at the calendar or NSDate time for doing that.