0

I am getting a crash saying that my assignment is nil, but the guard should cover that.

extension viewController: UIImagePickerControllerDelegate{

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]){
        imagePicker.dismiss(animated: true, completion: nil)
        guard let selectedImage = info[.originalImage] as? UIImage else {
            print("Image not found!")
            return
        }
        imageTaken.image = selectedImage <=== Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
    }
}

Doing a po in the debugger I get the following value

(lldb) po selectedImage <UIImage:0x281f058c0 anonymous {3024, 4032}>

Which is obviously not nil so am a bit confused. What am I missing?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Michael Rowe
  • 870
  • 2
  • 11
  • 27

0 Answers0