didFinishPickingMediaWithInfo

didFinishPickingMediaWithInfo

本文介绍了Swift 4.2 imagePickerController 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将聊天客户端从 swift 4 传递到 swift 4.2,我发现了问题.

Trying to pass chat client from swift 4 to swift 4.2 and with picker i found trouble.

UIImagePickerControllerEditedImage 不能下标类型的值'[String : Any]' 类型为索引'UIImagePickerController.InfoKey'

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)
}

推荐答案

方法签名已更改为

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

您应该会看到 func 名称的警告消息

You should see a warning message for the func name

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

Candidate 具有不匹配的类型 '(UIImagePickerController, [String :任何]) -> ()'

Candidate has non-matching type '(UIImagePickerController, [String : Any]) -> ()'

将imagePickerController(_:didFinishPickingMediaWithInfo:)"移动到另一个消除此警告的扩展

Move 'imagePickerController(_:didFinishPickingMediaWithInfo:)' to another extension to silence this warning

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

Make 'imagePickerController(_:didFinishPickingMediaWithInfo:)' private to silence this warning

要求 'imagePickerController(_:didFinishPickingMediaWithInfo:)'在这里声明 (UIKit.UIImagePickerControllerDelegate)

Requirement 'imagePickerController(_:didFinishPickingMediaWithInfo:)' declared here (UIKit.UIImagePickerControllerDelegate)

这篇关于Swift 4.2 imagePickerController 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 07:39