因为我使用 Swift 3 出现以下错误..
Cannot assign value of type '(LLSimpleCamera?, NSError?) -> Void' to type '((LLSimpleCamera?, Error?) -> Void)!'
有人知道怎么办吗? 这是我的代码..
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)
}
}
}
最佳答案
Swift 3
将 Objective C NSError
类型映射到协议(protocol) Error
(aka ErrorType
在 Swift 2
中)。
因此在闭包参数列表中,它希望将 Error
作为第二个参数的类型,而不是 NSError
。
但是在闭包内部你需要输入 case error
参数到 NSError
如果你想使用 .domain
/.code
/等
关于ios - 无法将类型 '() -> Void' 的值分配给 '(() -> Void)!',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39875485/