基本上,我正在将代码从swift 3应用程序迁移到swift 5应用程序,并且遇到以下错误:
不能使用索引类型为“ UIImagePickerController.InfoKey”的索引对类型为[[String:Any]”的值进行下标
我尝试查找苹果开发人员文档,将NSString转换为NSObject,并尝试组合数组地址来找出。如果有人将来也能提供有关如何解决此类错误的见解,我将不胜感激(我应该先检查开发人员文档吗?)
private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let mediaType = info[UIImagePickerControllerMediaType] as! NSString
if mediaType.isEqual(to: kUTTypeImage as String) {
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
if (newMedia == true) {
UIImageWriteToSavedPhotosAlbum(image,
self,
#selector(SingleObservationViewController.image(image:didFinishSavingWithError:contextInfo:)),
nil)
}
}
self.dismiss(animated: true, completion: nil)
}
获取错误:无法为索引为'UIImagePickerController.InfoKey'的类型[[String:Any]'下标
关于媒体类型声明及其在
中的用法让image = info [UIImagePickerControllerOriginalImage]为! UIImage