1
resposta

Problema no ImagePicker.swift

Estou tendo problema no trecho do código que recupera a foto pra usar no aplicativo.

No trecho do arquivo ImagePicker.swift :

private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        let foto = info[UIImagePickerControllerOriginalImage] as! UIImage
        delegate?.imagePickerFotoSelecionada(foto)
        picker.dismiss(animated: true, completion: nil)

Dá a seguinte mensagem: "Cannot subscript a value of type '[String : Any]' with an argument of type 'UIImagePickerController.InfoKey'""

Acredito se tratar de algum tipo de atualização, mas não sei como tratar.

Tô usando Swift 5, iOS 13.2.

Alguém ajuda?

Garanta sua matrícula hoje e ganhe + 2 meses grátis

Continue sua jornada tech com ainda mais tempo para aprender e evoluir

Quero aproveitar agora
1 resposta

https://stackoverflow.com/a/51342175/2616839

Segundo o Slack, no swift 4.2, mudou a assinatura do método para:

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

sendo possível acessar a imagem desse modo:

guard let selectedImage = info[.originalImage] as? UIImage else {
    fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
}