Unable to set type value to '() & # 8594; Void 'to' (() & # 8594; Void)! '

Since I am using Swift 3, the following error appears.

Cannot set value to type '(LLSimpleCamera ?, NSError?) → Void' to type '((LLSimpleCamera ?, Error?) → Void)!

Does anyone know what to do? here is my code ..

camera.onError = { (camera: LLSimpleCamera?, error: NSError?) -> Void in
        print("Camera error: \(error)")

        if error.domain == LLSimpleCameraErrorDomain {
            if error.code == Int(LLSimpleCameraErrorCodeCameraPermission.rawValue) || error.code == Int(LLSimpleCameraErrorCodeMicrophonePermission.rawValue) {

                let alertVC = UIAlertController(title: "Ooops!", message: "We need permission for the camera. Please go to your settings.", preferredStyle: .alert)
                let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
                let settingsAction = UIAlertAction(title: "Settings", style: .default) { (action) in
                    UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!)
                }

                alertVC.addAction(okAction)
                alertVC.addAction(settingsAction)

                self.present(alertVC, animated: true, completion: nil)
            }
        }
    }
+4
source share
1 answer

Swift 3maps the type of Objective-C NSErrorto the protocol Error(aka ErrorTypein Swift 2).

Therefore, in the list of closing parameters, it expects Erroras the second type of parameter instead NSError.

Error NSError, .domain/.code/etc.

+1

Source: https://habr.com/ru/post/1656815/


All Articles