I use NSTimer to update a label that shows the current time every minute. I start the timer for the full minute date (e.g. 2:23:00 instead of 2:22:17). The problem is that NSTimer does not work accurately, which means that it sometimes works too early (which leads to (for example) 2:23 pm, when it really is 2:24 pm).
Is there a fix / workaround?
EDIT: Here, as I start the timer:
NSTimer *clockTimer = [[NSTimer alloc] initWithFireDate:[NSDate nextFullMinuteDate] interval:60.0 target:self selector:@selector(updateClocks:) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:clockTimer forMode:NSDefaultRunLoopMode]; [clockTimer release];
Btw, I tried to add a few milliseconds to the fire date, this seems to help, but it seems like finding a suitable interval to add is a miss.
EDIT 2: Okay, so I manually set my timer to fire 0.05 seconds after a full minute, and then again after 60.0 seconds. Now here is what I registered in the called method:
0.048728 0.047153 0.046484 0.044883 0.043103
As you can see, NSTimer does not actually use the 60 second time interval, but a little shorter.
source share