我建议使用调度组:
func resetDevice(completion: () -> ()) { let dispatchGroup = DispatchGroup() for device in devices { dispatchGroup.enter() device.isValid = 0 DeviceManager.instance.updateDevice(device).call { response in print("device reset") dispatchGroup.leave() } } dispatchGroup.notify(queue: DispatchQueue.main) { // Some pre to execute when all devices have been reset }}每个设备都立即进入该组,但直到收到响应后才离开该组。在所有对象都离开组之前,不会调用最后的notify块。



