图像?不可转换为 UIImage:Xcode 在尝试使用原始图像时抛出错误 [英] UImage? isn't convertible to UIImage: Xcode throws error when trying to use original image

查看:20
本文介绍了图像?不可转换为 UIImage:Xcode 在尝试使用原始图像时抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    // The info dictionary may contain multiple representations of the image. You want to use the original.
    guard let selectedImage = info[.originalImage] as?
        UIImage else {
        fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
    }

    // Set photoImageView to display the selected image.
    photoImageView.image = selectedImage

    // Dismiss the picker.
    dismiss(animated: true, completion: nil)
}

我正在尝试构建一个允许您从库中选择图像的 iOS 应用程序,但它一直失败并显示错误UIImage?无法转换为 UIImage.有没有办法修复此错误或绕过它作为现在?我在 MacOS 10.14 上运行 Xcode 10.1.

I am trying to build an iOS app that allows you to pick an image from the library, but it keeps failing with the error "UIImage? is not convertible to UIImage. Is there a way to fix this error or bypass it as of now? I am running Xcode 10.1 on MacOS 10.14.

推荐答案

Replace .originalImageUIImagePickerControllerOriginalImage

Replace .originalImage with UIImagePickerControllerOriginalImage

这对我有用.

Xcode 版本:10.1

Swift 版本:4.0

This worked for me.

Xcode version: 10.1

Swift version: 4.0

这篇关于图像?不可转换为 UIImage:Xcode 在尝试使用原始图像时抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆