I have looked Here for solutions to this, and have tried several, none which worked. Maybe this problem I am having can help some people who did not get a solution from the link I provided.
I am trying to set up a camera, however, I am getting the following when I run the app.
Unexpectedly found nil while unwrapping an Optional value
this happens on the line indicated below:
func setupInputOutput() {
// if currentCamera != nil {
do {
let captureDeviceInput = try AVCaptureDeviceInput(device: currentCamera!) //Here error happens
captureSession.addInput(captureDeviceInput)
photoOutput?.setPreparedPhotoSettingsArray([AVCapturePhotoSettings(format: [AVVideoCodecKey: AVVideoCodecType.jpeg])], completionHandler: nil)
} catch {
print("error -- \(error)")
}
// }
}
I declare currentCamera as shown below:
var currentCamera: AVCaptureDevice?