- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"begin");
//队列
// dispatch_queue_t queue = dispatch_queue_create(0, 0);//子线程
dispatch_queue_t queue = dispatch_get_main_queue();//主线程
//创建定时器
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
//设置时间
uint64_t star = 2.0;//2秒后开始执行
uint64_t intervale = 1.0;//每隔1秒执行
dispatch_source_set_timer(timer,dispatch_time(DISPATCH_TIME_NOW, star * NSEC_PER_SEC) ,intervale * NSEC_PER_SEC ,0);
// //设置回调。方法一
// dispatch_source_set_event_handler(timer, ^{
// NSLog(@"1111======%@",[NSThread currentThre
dispatch_source_set_event_handler_f(timer, timerFire);
dispatch_resume(timer);
self.timer = timer;
}
//
void timerFire(void *parma){
NSLog(@"1111======%@",[NSThread currentThread]);//打印看看在什么线程上执行
}
网友评论