0
votes

I have the following code:

[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerCount:) userInfo:nil repeats:YES];

-(void)timerCount:(NSTimer *)timer
{
    NSTimeInterval dt = [timer timeInterval];
    // do something
}

The NSTimeInterval I got will be 0.5, the time interval I've put on scheduledTimerWithInterval, this means the timerCount will be called each 0.5 seconds.

But I now that there are some stuff as timeStamps, and I want to know if the NSTimer will call the timerCount method in PRECISELY 0.5 seconds each time.

2
Buy an atomic clock if you need a PRECISELY 0.5 seconds interval [[please state the required precision]]. - kennytm

2 Answers

0
votes

You won't get that using NSTimer on main thread as the timer is only called by event loop.

If you need maximal precision just create a thread with it's own message loop and schedule the timer there.

0
votes
 aTimer = [NSTimer timerWithTimeInterval:(1.0) target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];

        NSRunLoop *runner = [NSRunLoop currentRunLoop];
        [runner addTimer:aTimer forMode: NSDefaultRunLoopMode];


- (void)timerFired:(NSTimer*)theTimer
 {

    if(condition)
    { 
        //timer terminated
        [theTimer isinValid];
}

}