当前位置 : 主页 > 手机开发 > 其它 >

Swift 4.2 imagePickerController问题

来源:互联网 收集:自由互联 发布时间:2021-06-11
试图将聊天客户端从 swift 4传递到 swift 4.2并且使用选择器我发现了麻烦. UIImagePickerControllerEditedImage //无法使用索引类型为“UIImagePickerController.InfoKey”的类型'[String:Any]’下标 func image
试图将聊天客户端从 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)
}
方法签名已更改为

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

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

Instance method
‘imagePickerController(:didFinishPickingMediaWithInfo:)’ nearly
matches optional requirement
‘imagePickerController(
:didFinishPickingMediaWithInfo:)’ of protocol
‘UIImagePickerControllerDelegate’

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

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

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

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

网友评论