DispatchGroup:检查“进入"了多少 [英] DispatchGroup: check how many "entered"
问题描述
我正在使用 Swift 3 DispatchGroup
等待多个异步操作完成(根据 this answer 工作完美,符合预期.
I'm using Swift 3 DispatchGroup
to wait until multiple async operations are finished (according to this answer which works perfect and as expected.
有没有办法检查已经输入了多少操作,比如 dispatchGroup.count
或类似的东西?
Is there a way to check how many operations are entered already, like dispatchGroup.count
or something like that?
推荐答案
你可以在调试说明中看到进入组的次数:
You can see counts of enters to the group in debug description:
OS_dispatch_group: group[0x60000221d950] = { xref = 3, ref = 3,count = 2,gen = 0,waiters = 0,notifs = 1 }
OS_dispatch_group: group[0x60000221d950] = { xref = 3, ref = 3, count = 2, gen = 0, waiters = 0, notifs = 1 }
并从中提取 int 值:
and extract int value out of it:
let count = dispatchGroup.debugDescription.components(separatedBy: ",").filter({$0.contains("count")}).first?.components(separatedBy: CharacterSet.decimalDigits.inverted).compactMap{Int($0)}.first
这篇关于DispatchGroup:检查“进入"了多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!