Daniel Siebert Daniel Siebert - 1 year ago 80
Swift Question

Cannot assign value of type '() -> Void' to '(() -> Void)!'

Since I use Swift 3 the following error appears..

Cannot assign value of 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)!)


self.present(alertVC, animated: true, completion: nil)

Answer Source

Swift 3 maps Objective C NSError type to protocol Error(aka ErrorType in Swift 2).

So in closure parameters list it expects Error as second parameter's type instead of NSError.

But inside of closure you need to type case error parameter to NSError if you want to use .domain/.code/etc.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download