Search code examples
iosiphonexcode9swift4

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


Solution

  • 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.