title: AVCaptureDeviceInput Unexpectedly found nil while unwrapping an Optional value
body: <p>I'm trying to get the image of the capturing device but it keeps returning nil by <code>if let input...</code> and I can't find a solution.</p>
  
  <p>It tries to catch the error but it instantly cashes..</p>
  
  <pre><code>let backCamera = AVCaptureDevice.default(for: AVMediaType.video)
  
      do {
          if let input = try AVCaptureDeviceInput(device: backCamera!) as? AVCaptureInput {
              if (captureSession?.canAddInput(input))! {
                  captureSession?.addInput(input)
  
                  stillImageOutput = AVCapturePhotoOutput()
                  let settings = AVCapturePhotoSettings()
                  let settingsFormat = [AVVideoCodecKey : AVVideoCodecType.jpeg]
                  settings.previewPhotoFormat = settingsFormat
  
                  stillImageOutput?.capturePhoto(with: settings, delegate: self as! AVCapturePhotoCaptureDelegate)
  
                  if (captureSession?.canAddOutput(stillImageOutput!))! {
                      captureSession?.addOutput(stillImageOutput!)
  
                      previewLayer = AVCaptureVideoPreviewLayer(session: captureSession!)
                      previewLayer?.videoGravity = AVLayerVideoGravity.resizeAspect
                      previewLayer?.connection?.videoOrientation = AVCaptureVideoOrientation.portrait
                      cameraView.layer.addSublayer(previewLayer!)
  
                      captureSession?.startRunning()
                  }
              }
          }
  
  
      } catch let error as NSError {
          print("Error: \(error)")
      }
  </code></pre>