Created
May 4, 2018 07:03
-
-
Save zhangkn/91ba86f7ace93e7c744d437fafc4d1e5 to your computer and use it in GitHub Desktop.
:等2个异步操作都执行完毕后,再回到主线程执行操作
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 有这么1种需求 | |
首先:分别异步执行2个耗时的操作 | |
其次:等2个异步操作都执行完毕后,再回到主线程执行操作 | |
// 如果想要快速高效地实现上述需求,可以考虑用队列组 | |
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(), ^{ | |
// 等前面的异步操作都执行完毕后,回到主线程... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment