I have the following code :
func startCameraFromViewController(viewController: UIViewController, withDelegate delegate:
protocol<UIImagePickerControllerDelegate, UINavigationControllerDelegate>) -> Bool {
if (UIImagePickerController.isSourceTypeAvailable(.Camera) == false) {
return false
}
let cameraController = UIImagePickerController()
cameraController.sourceType = .Camera
cameraController.mediaTypes = [kUTTypeMovie as String]
cameraController.allowsEditing = false
cameraController.delegate = delegate
presentViewController(cameraController, animated: true, completion: nil)
return true
}
It is being called as follows :
func recordVideoButtonTapped() {
startCameraFromViewController(self, withDelegate: self)
}
But for some reason, I am getting the following error
fatal error: unexpectedly found nil while unwrapping an Optional value
on this line :
presentViewController(cameraController, animated: true, completion: nil)
Please help debug.
This question is different from
What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?
which is a more general question relating to unwrapping of optionals
This question pertains specifically to UIImagePickerController