I am trying to make a stop watch with NSTimer.
I gave the following code:
nst_Timer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(showTime) userInfo:nil repeats:NO];
and it is not working in milliseconds. It takes more than 1 millisecond.
Don’t use
NSTimerthat way. NSTimer is normally used to fire a selector at some time interval. It isn’t high precision and isn’t suited to what you want to do.What you want is a High resolution timer class (using
NSDate):Output:
Main:
Edit: Added methods for
-timeElapsedInMillisecondsand-timeElapsedInMinutesTimer.h:
Timer.m