Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Swift error saying it cannot assign to property due to it being a 'let' constant

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading