title: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value. Getting image from Gallery swift
body: <p>I am trying to get an image from the gallery through a button but I am getting this error: </p>
  
  <blockquote>
    <p>Thread 1: Fatal error: Unexpectedly found nil while unwrapping an
    Optional value. </p>
  </blockquote>
  
  <p>I have looked at all the other questions that are
  similar to mine, but for some reason, I am not able to solve my
  problem.</p>
  
  <pre><code>class ViewController: UIViewController, VNDocumentCameraViewControllerDelegate,  UINavigationControllerDelegate, UIImagePickerControllerDelegate  {
  
      var textRecognitionRequest = VNRecognizeTextRequest()
      var recognizedText = ""
      var text2 = "";
  
      @IBOutlet weak var imageTest: UIImageView!
      @IBOutlet weak var centreView: CardView!
      @IBOutlet weak var centreViewBorder: UIView!
      @IBOutlet weak var circleButton: UIButton!
  
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
          imageTest = UIImageView()
  ```
  
  ```
  IBAction func uploadImage(_ sender: UIButton) {
          let imagePicker = UIImagePickerController()
          imagePicker.delegate = self
          imagePicker.sourceType = .photoLibrary
          self.present(imagePicker, animated: true, completion: nil)
  
      }
     func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
          guard let image = info[.originalImage] as? UIImage else {
              fatalError("Error")
          }
          imageTest!.image = image
      dismiss(animated: true, completion: nil)
  
      }
  func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
      dismiss(animated: true, completion: nil)
  }
  </code></pre>
  
  <pre><code>
  
  </code></pre>