本文介绍了错误:无法用索引类型为"UIImagePickerController.InfoKey"的下标"[String:Any]"类型的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试重建Apple测试应用程序以通过CoreML进行图像检测,但是出现错误:
I am trying to rebuild the Apple test App for image detection via CoreML, but I have the error:
extension ImageClassificationViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
picker.dismiss(animated: true)
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
imageView.image = image
updateClassifications(for: image)
}
该错误出现在行中:
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
推荐答案
您似乎正在使用Xcode 10/iOS12.委托方法的签名已更改.
It appears you are using Xcode 10/iOS 12. The signature of the delegate method changed.
对于info
键,请使用UIImagePickerController.InfoKey
而不是String
.
Use UIImagePickerController.InfoKey
instead of String
for the info
keys.
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any])
然后使用.originalImage
代替UIImagePickerControllerOriginalImage
.
extension ImageClassificationViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
picker.dismiss(animated: true)
let image = info[.originalImage] as! UIImage
imageView.image = image
updateClassifications(for: image)
}
这篇关于错误:无法用索引类型为"UIImagePickerController.InfoKey"的下标"[String:Any]"类型的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!