gcd延迟执行

2017-09-11  本文已影响50人  lizhi_boy

1s后执行


                dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t) (1.0 * NSEC_PER_SEC));
                
                dispatch_after(time, dispatch_get_main_queue(), ^(void) {
//你的操作
});
dispatch_group_t group =  dispatch_group_create();
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 // 执行1个耗时的异步操作
});
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 // 执行1个耗时的异步操作
});
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
 // 等前面的异步操作都执行完毕后,回到主线程...
});
上一篇 下一篇

猜你喜欢

热点阅读