[英]iOS Swift 3, Alamorfire: Wait for all image uploading to be finished before calling a function
一种解决方案是使用DispatchGroup 。
//Create a dispatch group
let dispatchGroup = DispatchGroup()
for picture in listOfPicturesToUpload {
//Enter the group
dispatchGroup.enter()
self.upload(picture, completion:{
//Leave the group on upload completion
dispatchGroup.leave
})
}
//Called when all the requests are finished
dispatchGroup.notify(queue: DispatchQueue.global(qos: .background)) {
//Call the save function as all the requests are finished.
self.save()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.