对成员Swift 3的含糊不清的引用

编程入门 行业动态 更新时间:2024-10-05 03:27:16
本文介绍了对成员Swift 3的含糊不清的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将项目从Swift 2.3迁移到Swift 3,并且遇到了预期的困难.

I am migrating my project from Swift 2.3 to Swift 3. And having difficulty as expected.

此处是使用 OAuthSwift 的OAuth函数.我试图转换

Here is a function which is being used for OAuth, using OAuthSwift. I have tried to convert

class func OAuthSwiftAuthorization(inViewController viewController: UIViewController, withOAuthInfo info:FitnessTracker, successHandler:@escaping MyOAuthNewSuccessHandler, failure: @escaping ((_ error: NSError) -> Void)) { let oauthswift = OAuth2Swift( consumerKey: info.consumerKey, consumerSecret: info.consumerSecret, authorizeUrl: info.authorizeUrl, accessTokenUrl: info.accessTokenUrl, responseType: info.responseType ) oauthswift.authorizeURLHandler = SafariURLHandler(viewController: viewController, oauthSwift: oauthswift) oauthswift.accessTokenBasicAuthentification = true oauthswift.allowMissingStateCheck = true oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in successHandler(credential, response, parameters) }) { (error) in failure(error: error) print(error.localizedDescription) } }

但是我在

oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in

错误状态

对成员'authorize(withCallbackURL:scope:state:parameters:headers:success:failure :)'的引用不明确

Ambiguous reference to member 'authorize(withCallbackURL:scope:state:parameters:headers:success:failure:)'

这是Swift 2的工作代码.

Here is the working code from Swift 2.

oauthswift.authorizeWithCallbackURL( URL(string: info.callBackUrl)!, scope: info.scope, state:info.state, success: { credential, response, parameters in successHandler(credientials: credential, response: response, params: parameters) }, failure: { error in failure(error: error) print(error.localizedDescription) } )

更新:

我键入成功和失败后,错误不会出现.这很好:

Error does not appear unitil I type success and faliure handelrs. This complies fine:

oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in // successHandler(credential, response, parameters) }) { (erorr) in // failure(error: error }

所以请指导我,谢谢.

推荐答案

我认为此问题是由于Swift的类型推断与闭包相结合而引起的. 您可以尝试以下操作之一:

I think the problem is caused by some shortcomings of Swift's type inference in combination with closures. You could try one of the following:

例如,不要使用结尾的闭包

Either don't use trailing closures, e.g.

oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in successHandler(credential, response, parameters) }, failure: { (error) in failure(error: error) print(error.localizedDescription) })

或提供明确的错误类型,例如

or provide an explicit type for error, e.g.

oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in successHandler(credential, response, parameters) }) { (error: Error) in failure(error: error) print(error.localizedDescription) }

更多推荐

对成员Swift 3的含糊不清的引用

本文发布于:2023-11-26 10:05:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633654.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不清   成员   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!