ios – 无法将类型'() – > Void’的值赋给'(() – > Void)!’

ios – 无法将类型'() – > Void’的值赋给'(() – > Void)!’,第1张

概述由于我使用 Swift 3,出现以下错误.. Cannot assign value of type ‘(LLSimpleCamera?, NSError?) -> Void’ to type ‘((LLSimpleCamera?, Error?) -> Void)!’ 有谁知道该怎么办? 这是我的代码.. camera.onError = { (camera: LLSimpleCamera?, 由于我使用 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类型映射到协议Error(在Swift 2中也称为ErrorType).

所以在闭包参数列表中,它期望Error作为第二个参数的类型而不是NSError.

但是在闭包内部,如果要使用.domain / .code / etc,则需要为NSError键入case error参数.

总结

以上是内存溢出为你收集整理的ios – 无法将类型'() – > Void’的值赋给'(() – > Void)!’全部内容,希望文章能够帮你解决ios – 无法将类型'() – > Void’的值赋给'(() – > Void)!’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1030922.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存