在从旧版本的swift转换时,我会得到警告
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: AnyObject])
警告是
实例方法 'imagePickerController(:didfinishpickingmediawithinfo :)'几乎 匹配可选要求 'ImagePickerController(:didfinishpickingmediawithinfo :)' uiimagePickerControllerDelegae
这里的问题在于,据我所知,它抱怨什么以及它所说的几乎是100%相同的。如何解决此警告?
在较新的Swift版本中,方法应为
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
然后,警告不会出现。
这是Swift 5.2
中的正确答案func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let tempImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
imgRoom.image = tempImage
self.dismiss(animated: true, completion: nil)
}