目前,我正在尝试深入 PHPickerViewController 以从照片中同时选择多个图像。所以我想要用户选择的图像数组,我尝试了太多方法但没有运气。这是我的代码,请告诉我有最佳实践吗?
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)")
}
})
}
}