I'm trying to upload multiple images to firebase storage, and the app needs to do something after the uploading tasks finish. I did some research, and I found barrier is useful in this case. I followed the tutorial, but it seems my code is not working properly. What did I miss? Here is the code:
func uploadImages(completion: (()->Void)){
// creating a queue
let uploadImagesQueue = DispatchQueue(label: "upLoadImages", attributes: .concurrent)
for i in 0..<numOfImages{
uploadImagesQueue.async{
// upload each of the images
}
}
uploadImagesQueue.async(flags: .barrier){
completion()
}
}
The problem of this code is that completion()
runs before all the upload parts finish. How can I fix this?