Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 维玛?isn';无法转换为UIImage:Xcode在尝试使用原始映像时抛出错误_Ios_Swift_Uiimage_Uiimagepickercontroller - Fatal编程技术网

Ios 维玛?isn';无法转换为UIImage:Xcode在尝试使用原始映像时抛出错误

Ios 维玛?isn';无法转换为UIImage:Xcode在尝试使用原始映像时抛出错误,ios,swift,uiimage,uiimagepickercontroller,Ios,Swift,Uiimage,Uiimagepickercontroller,我正在尝试构建一个iOS应用程序,允许您从库中拾取图像,但它不断失败,错误为“UIImage”无法转换为UIImage。是否有办法修复此错误或从现在起绕过此错误?我正在MacOS 10.14上运行Xcode 10.1。信息[.originalImage]是Any?值。它好像可以包含UIImage?值或nil。因此,请尝试: func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWit

我正在尝试构建一个iOS应用程序,允许您从库中拾取图像,但它不断失败,错误为“UIImage”无法转换为UIImage。是否有办法修复此错误或从现在起绕过此错误?我正在MacOS 10.14上运行Xcode 10.1。

信息[.originalImage]是Any?值。它好像可以包含UIImage?值或nil。因此,请尝试:

 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)
}

将该问号添加到UIImage。仅此而已。

.originalImage
替换为
UIImagePickerControllerOriginalImage

这对我有用。 Xcode版本:10.1
Swift版本:4.0

使用正确的方法签名开始:
func imagePickerController(picker:UIImagePickerController,didFinishPickingMediaWithInfo:[UIImagePickerController.InfoKey:Any])
。在您的guard语句中,我认为您不需要?在as.as@rmaddy已经在上面进行了注释之后,委托方法的签名是错误的。info参数的类型必须为“[UIImagePickerController.InfoKey:Any]”,请参阅
guard guard let selectedImage = info[.originalImage] as? UIImage?  else { ... }