Skip to content

Instantly share code, notes, and snippets.

@leepfrog
Created July 31, 2012 00:11
Show Gist options
  • Select an option

  • Save leepfrog/3212220 to your computer and use it in GitHub Desktop.

Select an option

Save leepfrog/3212220 to your computer and use it in GitHub Desktop.
_clockFormat = [[NSDateFormatter alloc] init];
[_clockFormat setTimeStyle:NSDateFormatterLongStyle];
[_clockFormat setLocale:[NSLocale systemLocale]];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
_clockTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(_clockTimer, DISPATCH_TIME_NOW, kClockUpdateInterval * NSEC_PER_SEC, 0);
dispatch_source_set_event_handler(_clockTimer, ^{
self.clock.text = [_clockFormat stringFromDate:[NSDate date]];
NSLog(@"%@",[_clockFormat stringFromDate:[NSDate date]]);
});
// now that our timer is all set to go, start it
dispatch_resume(_clockTimer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment