【发布时间】:2020-10-30 16:17:07
【问题描述】:
我有一组对象,我必须使用 for-loop 和 DispatchGroup 进行迭代。离开for-loop内的群时,需要调用continue吗?
let group = DispatchGroup()
for object in objects {
group.enter()
if object.property == nil {
group.leave()
continue // does calling this have any effect even though the group is handling it?
}
// do something with object and call group.leave() when finished
}
group.notify(...
【问题讨论】:
-
顺便说一句,你提到“用对象做某事”......不用说,如果那个“某事”不是异步的,那么你根本不应该使用组。跨度>
-
@Rob 谢谢,我想让代码尽可能简单,只是为了直截了当。我不会将它用于常规循环。我实际上用它从 Firebase 中提取一些数据,我必须通过多个参考,例如 postsRef > blockedRef > userIdRef > followingRef
-
有道理。
标签: ios swift grand-central-dispatch dispatchgroup