Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImage must conform to _ObjectiveCBridgeable in PHPickerViewControllerDelegate callback

I have reviewed the WWDC2020 video explaining how to adopt the new PHPickerViewController API. I have also seen several blogs showing exactly the following code.

func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
    if let result = results.first, result.itemProvider.canLoadObject(ofClass: UIImage.self) {
        result.itemProvider.loadObject(ofClass: UIImage.self) { (image, error) in
            DispatchQueue.main.async {
                self.parent.didCapture(image)
            }
        }
    } else {
        parent.didCapture(nil)
    }
}

However, this fails for me and the error is quite bizarre.

UIImage must confirm to _ObjectiveCBridgable

I will include a screenshot because it is quite unbelievable

enter image description here

Hardware: M1 chipset

IDE: Xcode 12.4


1 Answers

Type cast image as UIImage before using, that should solve the issue.

if let typeCastedImage = image as? UIImage {
  self.parent.didCapture(typeCastedImage)
}
like image 74
PK-V Avatar answered Jun 24 '26 05:06

PK-V



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!