由于我使用Swift 3,因此出现以下错误。
无法将类型'((LLSimpleCamera ?, NSError?)-> Void'的值分配为类型'(((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
将目标CNSError
类型映射到协议Error
(也称为 ErrorType
in Swift 2
)。
因此,在闭包参数列表中,它期望Error
作为第二个参数的类型,而不是NSError
。
但是在闭包内部,如果要使用/ / etc error
,NSError
则需要键入case参数。.domain
.code
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句