[英]Ambiguous reference to member Swift 3
I am migrating my project from Swift 2.3 to Swift 3. And having difficulty as expected. 我正在将我的项目从Swift 2.3迁移到Swift 3.并且遇到了预期的困难。
Here is a function which is being used for OAuth, using OAuthSwift . 这是一个使用OAuthSwift用于OAuth的函数 。 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)
}
}
But I am getting an error at 但是我收到了错误
oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in
Error states 错误状态
Ambiguous reference to member 'authorize(withCallbackURL:scope:state:parameters:headers:success:failure:)'
对成员'authorize的不明确引用(withCallbackURL:scope:state:parameters:headers:success:failure :)'
Here is the working code from Swift 2. 这是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)
}
)
UPDATE: 更新:
Error does not appear unitil I type success and faliure handelrs. 错误没有出现unitil我输入成功和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
}
So Please guide me Thanks. 所以请指导我谢谢。
I think the problem is caused by some shortcomings of Swift's type inference in combination with closures. 我认为这个问题是由Swift的类型推断和闭包的一些缺点引起的。 You could try one of the following:
您可以尝试以下方法之一:
Either don't use trailing closures, eg 要么不使用尾随闭包,例如
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, eg 或提供错误的显式类型,例如
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)
}
For reference: This kind of error appears when there's more than one variable/method with the same name, does your oauthswift
has more than one "thing" called "authorize"? 供参考:当有多个具有相同名称的变量/方法时,会出现这种错误,你的
oauthswift
是否有多个名为“authorize”的“东西”? like another method? 喜欢另一种方法? My error was that i declared:
我的错误是我宣布:
let fileManager = FileManager()
and in 并在
let _ = try localFileManager.createDirectory(...)
I got the same error, changing the variable name in localFileManager
fixed it. 我得到了同样的错误,更改
localFileManager
的变量名称修复它。
I got the same error Ambiguous reference to member with the same method on converting it from Swift 4 to Swift 5 . 我得到了同样的错误对成员的模糊引用,使用相同的方法将它从Swift 4转换为Swift 5 。 Looks like the completion handler has been changed to support the new Result type.
看起来已完成处理程序已更改为支持新的Result类型。 Changing the completing handler to below fixed the issue for me,
将完成处理程序更改为以下为我修复了问题,
oauthVarSwift.authorize( withCallbackURL: URL(string: "")!,
scope: "", state:"", completionHandler: { result in
switch result {
case .success(let credential, let response, let parameters):
print(credential.oauthToken)
case .failure(let error):
print(error)
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.