Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializer for conditional binding must have Optional type, not 'AVCaptureVideoPreviewLayer'

2 errors occur after migrating to swift 4.

First error:

Initializer for conditional binding must have Optional type, not AVCaptureVideoPreviewLayer.

enter image description here

Second error:

Initializer for conditional binding must have Optional type, not [AVCaptureDevice].

enter image description here

How Should I correct these errors?

Thanks

like image 378
Mansi Dobariya Avatar asked Oct 21 '25 12:10

Mansi Dobariya


2 Answers

I think you just remove if let ... condition and changes

like simple

let cameraLayer = AVCaptureVideoPreviewLayer(session: self.cameraSession)

And same for second error means you should use directly videoDevices no need to use if let... condition.

like image 103
iPatel Avatar answered Oct 23 '25 04:10

iPatel


The initializer of AVCaptureVideoPreviewLayer doesn't return an optional. Thus, the if condition is always true, and the if statement ist useless. You should remove the if and it's braces.

like image 45
clemens Avatar answered Oct 23 '25 04:10

clemens