1. // MARK: - 延迟执行
    2. - (void)delay {
    3. /**
    4. 从现在开始,经过多少纳秒,由"队列"调度异步执行 block 中的代码
    5. 参数
    6. 1. when 从现在开始,经过多少纳秒
    7. 2. queue 队列
    8. 3. block 异步执行的任务
    9. */
    10. dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC));
    11. void (^task)() = ^ {
    12. NSLog(@"%@", [NSThread currentThread]);
    13. };
    14. // 主队列
    15. // dispatch_after(when, dispatch_get_main_queue(), task);
    16. // 全局队列
    17. // dispatch_after(when, dispatch_get_global_queue(0, 0), task);
    18. // 串行队列
    19. dispatch_after(when, dispatch_queue_create("itheima", NULL), task);
    20. NSLog(@"come here");
    21. }
    22. - (void)after {
    23. [self.view performSelector:@selector(setBackgroundColor:) withObject:[UIColor orangeColor] afterDelay:1.0];
    24. NSLog(@"come here");
    25. }