Cannot assign value type mismatch swift

407 views Asked by At

I have the following code snippet.

 camera.onDeviceChange = { [weak self] (camera: LLSimpleCamera!, device: AVCaptureDevice!) -> Void in
      print("Device changed.")
 }

This used to work fine in Swift 2, but now I am getting the following error message:

Cannot assign value of type '(LLSimpleCamera!, AVCaptureDevice!) -> Void' to type '((LLSimpleCamera?, AVCaptureDevice?) -> Void)!'

Not really sure how to change this, I tried matching the type by changing the ! to optionals and then adding ! after the void, however this didn't work.

1

There are 1 answers

0
Bhavin Bhadani On BEST ANSWER

Your error suggest type mismatch that means LLSimpleCamera! != LLSimpleCamera? .. there is no need to define type. .. you can use it something like

camera.onDeviceChange = { [weak self] (camera, device) -> Void in
   print("Device changed.")
}