-1

I am trying to get a photo from the system album and using below code:

public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
        picker.dismiss(animated: true, completion: nil)

//        var image: UIImage? = info[UIImagePickerController.InfoKey.editedImage.rawValue] as? UIImage

        guard var image = info[.originalImage] as? UIImage else { return }

//        var image = info.index(forKey: UIImagePickerController.InfoKey.editedImage.rawValue) as? UIImage

        if (image == nil ) {
//            image = info[UIImagePickerControllerOriginalImage] as? UIImage
            image = info.index(forKey: UIImagePickerController.InfoKey.originalImage.rawValue) as? UIImage
        }

But the xcode always warns me:

“Cannot subscript a value of type '[String : Any]' with an index of type 'UIImagePickerController.InfoKey'”

I don't know how to change to continue.

Kaaaaai
  • 113
  • 1
  • 10

1 Answers1

0

Check the didFinishPickingMediaWithInfo method signature. It should be similar to this,

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

        guard let image = info[.originalImage] as? UIImage else { return }

    }
Kamran
  • 14,987
  • 4
  • 33
  • 51
  • Can you show your code that you tried? – Kamran Jun 19 '19 at 08:50
  • Did you notice any difference in the method signatures? – Kamran Jun 19 '19 at 08:56
  • There is a difference between `didFinishPickingMediaWithInfo info: [String: Any])` and `didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {` in your and above method signatures. Please compare carefully. – Kamran Jun 19 '19 at 09:03