Here is the snippet of the code:
public var captureDevice: CaptureDevice?
...
guard let captureDeviceTest = AVCaptureDevice.DiscoverySession.init(
deviceTypes: [AVCaptureDevice.DeviceType.builtInWideAngleCamera],
mediaType: AVMediaType.video,
position: cameraPosition).devices.first else {
return
}
self.captureDevice = captureDeviceTest
if let captureDevice = self.captureDevice {
...
// This is where error occurs
if captureDevice.isExposureModeSupported(.continuousAutoExposure) {
captureDevice.exposureMode = .continuousAutoExposure
}
The error I am getting is: Cannot assign to property: 'captureDevice' is a 'let' constant. I tried suggestion here to use inout but despite placing that in various places, it still didn’t work for me.
Any swift experts can help me out here?
>Solution :
You are accessing the local variable captureDevice, not the struct’s captureDevice variable.
Just replace the line causing the error to the following:
self?.captureDevice.exposureMode = .continuousAutoExposure
Note the self?. before captureDevice.