×
广告

稳定可靠的 Timer

96
Liberalism
2018.01.17 16:07 字数 0
- (void)setUpTimer {
    
    dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
    
    dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
    
    dispatch_source_set_event_handler(timer, ^{
    
        NSLog(@"线程是 - %@", [NSThread currentThread]);
    });
    
    dispatch_resume(timer);
    
   //  全局变量引用一下
    self.timer = timer;
}

工作笔记
Web note ad 1