uint64_tinterval =2*NSEC_PER_SEC;
//創(chuàng)建一個專門執(zhí)行timer回調(diào)的GCD隊列
dispatch_queue_tqueue =dispatch_queue_create("my queue",0);
//創(chuàng)建Timer
_timer=dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,0,0, queue);
//使用dispatch_source_set_timer函數(shù)設(shè)置timer參數(shù)
dispatch_source_set_timer(_timer,dispatch_time(DISPATCH_TIME_NOW,0), interval,0);
//設(shè)置回調(diào)
dispatch_source_set_event_handler(_timer, ^()
{
NSLog(@"Timer %@", [NSThreadcurrentThread]);
});
//dispatch_source默認(rèn)是Suspended狀態(tài)斟或,通過dispatch_resume函數(shù)開始它
dispatch_resume(_timer);