Currently, I am trying to dive into PHPickerViewController for select multiple image at same time from Photos. so I want to array of image that selected by user, i tried it too many way but no luck. This is my code please tell me there is an best practice for to do it?
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
picker.dismiss(animated: true, completion: nil)
var images: [UIImage?] = []
var totalConversionsCompleted = 0
for (index,result) in results.enumerated() {
result.itemProvider.loadObject(ofClass: UIImage.self, completionHandler: { (object, error) in
let image = object as? UIImage
images.append(image)
totalConversionsCompleted += 1
if totalConversionsCompleted == index {
print("completion happen \(images)")
}
})
}
}
I got it working using single
DispatchGroup
. This is my delegate method implementation: