0

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.

okami
  • 2,093
  • 7
  • 28
  • 40
  • 1
    Buy an atomic clock if you need a PRECISELY 0.5 seconds interval [[please state the required precision]]. – kennytm May 29 '10 at 15:01

2 Answers2

0
 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];
}

}

NANNAV
  • 4,875
  • 4
  • 32
  • 50
0

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.

Piotr Czapla
  • 25,734
  • 24
  • 99
  • 122