First you have to calculate your countdown time, in seconds, and put it in the instance variable (ivar)
NSTimeInterval totalCountdownInterval;
I think in order to maintain good accuracy (NSTimer shooting can be turned off for 100 ms and errors will add up), you should write down the start date and put it in another ivar:
NSDate* startDate = [NSDate date];
Then you can start the timer at regular (1 second here) intervals repeatedly calling the method on your class
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(checkCountdown:) userInfo:nil repeats:YES];
And in this method, you check the elapsed time for the total countdown time and update the interface
-(void) checkCountdown:(NSTimer*)_timer { NSTimeInterval elapsedTime = [[NSDate date] timeIntervalSinceDate:startDate]; NSTimeInterval remainingTime = totalCountdownInterval - elapsedTime; if (remainingTime <= 0.0) { [_timer invalidate]; } }
source share