2
votes

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

2

2 Answers

5
votes

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.

1
votes

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.