gpt4 book ai didi

ios - 尝试从照片库将图像加载到 UIImageView 时出现 Swift 4 错误

转载 作者:行者123 更新时间:2023-11-30 11:18:12 25 4
gpt4 key购买 nike

我一直在尝试修复从照片应用程序库导入图片时出现的错误。我查看了一下,发现它是一个字典键值问题?我很困惑任何帮助都会很棒。下面的代码以及错误。

@IBAction func onClickPickImage(_ sender: Any) {

imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = true
present(imagePicker, animated: true, completion: nil)

}
}

extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {

private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

if let image = info[UIImagePickerControllerOriginalImage] as? Any {
img.image = image
}

dismiss(animated: true, completion: nil)
}

错误 '无法使用 UIImagePickerController.InfoKey 类型的索引为 [String : Any] 类型的值添加下标

最佳答案

应该是这样的

let tempImage = info[UIImagePickerControllerOriginalImage] as! UIImage

对于可选绑定(bind),请使用如下代码:

if let image = info[UIImagePickerControllerOriginalImage] as? UIImage{

}

关于ios - 尝试从照片库将图像加载到 UIImageView 时出现 Swift 4 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51567679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com