小编典典

Swift 4.2 imagePickerController问题

swift

尝试将聊天客户端从swift 4传递到swift 4.2,并使用选择器发现问题。

UIImagePickerControllerEditedImage无法用索引类型为“
UIImagePickerController.InfoKey”的下标“ [String:Any]”的值

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

    if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
        self.userProfileImage.contentMode = .scaleAspectFit
        self.userProfileImage.image = pickedImage
    }

    picker.dismiss(animated: true, completion: nil)
}

阅读 283

收藏
2020-07-07

共1个答案

小编典典

方法签名已更改为

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])

您应该看到功能名称的警告消息

实例方法’imagePickerController( :didFinishPickingMediaWithInfo :)’与
协议’UIImagePickerControllerDelegate’的 可选要求 ‘imagePickerController(
:didFinishPickingMediaWithInfo :)’几乎匹配

候选人的类型不匹配’(UIImagePickerController,[String:Any])->()’

将’imagePickerController(_:didFinishPickingMediaWithInfo :)’移至另一个扩展名以使此警告静音

将’imagePickerController(_:didFinishPickingMediaWithInfo :)’设为私有可消除此警告

在此处声明的要求’imagePickerController(_:didFinishPickingMediaWithInfo
:)’(UIKit.UIImagePickerControllerDelegate)

2020-07-07