swift3 - 调度组 : check how many "entered"

标签 swift3 grand-central-dispatch

我正在使用 Swift 3 DispatchGroup等待多个异步操作完成(根据 this answer,它运行完美且符合预期。

有没有办法检查已经输入了多少操作,比如 dispatchGroup.count或类似的东西?

最佳答案

您可以在调试说明中看到进入组的次数:

OS_dispatch_group: group[0x60000221d950] = { xref = 3, ref = 3, count = 2, gen = 0, waiters = 0, notifs = 1 }



并从中提取 int 值:
let count = dispatchGroup.debugDescription.components(separatedBy: ",").filter({$0.contains("count")}).first?.components(separatedBy: CharacterSet.decimalDigits.inverted).compactMap{Int($0)}.first

关于swift3 - 调度组 : check how many "entered",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45610271/

相关文章:

swift - 从一个调度队列调用代码以在另一个调度队列中运行

ios - CIFilter似乎在GPU上失败

ios - 如何在 swift 3 中删除 Tabbar 项目

iOs:(Swift 3)我用 var 变量初始化:[[Any]] = [],但出现错误消息 [type 'Any' has no subscript members]

Swift:在 View 出现之前从异步调用中检索值

ios - 使用 dispatch_async 在 willDisplayCell 中很有用

ios - dataWithContentsOfURL(线程)和dataTaskWithURL之间有什么区别吗?

swift3 - 在 Swift 3 中将 JSON 字符串转换为字典

Swift 编译错误 : 'case' label can only appear inside a 'switch' statement?

ios - swift 火力基地 : Cannot store object of type _SwiftValue at fileURL