Error=Extra trailing closure passed in call,

Viewed 8204
    //creates the session
    let session = AVCaptureSession()

    //Defines the capture device
   AVCaptureDevice.default(for: AVMediaType.video)
   {
      let input = AVCaptureDeviceInput(device: captureDevice)
      session.addInput(input)
    }

Not sure how to solve this error any help would be greatly appreciated

1 Answers

AVCaptureDevice.default has a return value. You have to assign it to a variable.

And since the value is optional unwrap it safely

guard let captureDevice = AVCaptureDevice.default(for: AVMediaType.video),
      let input = try? AVCaptureDeviceInput(device: captureDevice) else { return }
session.addInput(input)
Related