Food Tracker Tutorial

Hey guys i'm new at this in fact is the first time i try coding and im doing the foos tracker tutorial but ive run into some errors and i cant seem to solve them. the first one is the


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

that one has the yellow warning saying instance method


and the other one is the

guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {

fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")

}

which says "cannot subscript a value of type '[String : Any*' with an index of type 'ultimatePickerContriller.infoKey


ive been stuck in this for hours and im following the tutorial and cant seem to sove this

HELP PLS!!!

Replies

The index you pass to the dictionary is not a String, but a UIImage.


Replace with the key string (could not check exactly):

info[UIImagePickerController.InfoKey] as? UIImage

> im following the tutorial and cant seem to sove this


Search on it here...it's known to be broken in more than one place, so...


Rather than fight it, tho, put it on the shelf and find something more current that also helps you learn instead of chasing your tail.

Hi, I'm also new to coding in swift and Xcode.

I've also been following this tutorial, got the same warning and error (which didn't let me change the image in the imageView), and somehow (I don't know how) I found the fix for this one.


This is what i got:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        // The info dictionary may contain multiple representations of the image. You want to use the original.
        guard let selectedImage = info[UIImagePickerController.InfoKey(rawValue: UIImagePickerController.InfoKey.originalImage.rawValue)] as? UIImage else {
            fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
            }
        
        // Set photoImageView to display the selected image.
        photoImageView.image = selectedImage
        
        // Dismiss the picker.
        dismiss(animated: true, completion: nil)
    }


Ran the simulator and now it works for me.

Hope it helps.