多线程定时器====
-(void)testGCDTime
{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
int64_t interval = (int64_t)(1 * NSEC_PER_SEC);
dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC));
dispatch_source_set_timer(source, start, interval, 0);
dispatch_source_set_event_handler(source, ^{
static int number = 0;
NSLog(@"%d", number);
number++;
if (number == 6) {
dispatch_source_cancel(source);
NSLog(@"Cancle timer.");
}
});
dispatch_resume(source);
}