使用GCD的完成区块 [英] Completion block using GCD
问题描述
我正在开发一个需要完成块和障碍"功能的应用程序.
据我所知,NSOperation
API具有completionBlock
属性,而GCD API具有dispatch_barrier_(a)sync
函数来处理障碍需求.
I am developing an app that requires a completion block and a "barrier" functionality.
As far as I know, NSOperation
API has a completionBlock
property and GCD API has the dispatch_barrier_(a)sync
function to handle the barrier needs.
我该怎么做才能满足这两个需求? 谢谢!
What should I do in order to accomplish both of the needs? Thanks!
推荐答案
dispatch_group应该具有您需要的所有内容.只需为您的工作单位使用dispatch_group_async/dispatch_group_enter,然后为您的完成处理程序派遣dispatch_group_notify.
dispatch_group should have all the pieces you need. Just dispatch_group_async/dispatch_group_enter for your work units, then dispatch_group_notify for your completion handler.
这篇关于使用GCD的完成区块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!