Hi I have an app where one of the features on the main page is a countdown to a certain date.
This is my code in my viewdidload:
Code:
destinationDate = [[NSDate dateWithTimeIntervalSince1970:1358303211] retain];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel:) userInfo:nil repeats:YES];
and my updatelabel method:
Code:
-(void)updateLabel:(NSTimer *)timer {
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int units = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;
NSDateComponents *components = [calendar components:units fromDate:[NSDate date] toDate:destinationDate options:0];
daysLabel.text = [NSString stringWithFormat:@"%d", [components day]];
hoursLabel.text = [NSString stringWithFormat:@"%d", [components hour]];
minutesLabel.text = [NSString stringWithFormat:@"%d", [components minute]];
}
This works great except it takes a little long to show up upon app launch. Is there anyway to reduce the time it takes to execute this?
Thanks