gpt4 book ai didi

ios - 对成员 Swift 3 的模糊引用

转载 作者:技术小花猫 更新时间:2023-10-29 10:47:53 26 4
gpt4 key购买 nike

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

这是一个用于 OAuth 的函数,使用 OAuthSwift .我试过转换

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

错误状态

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

这是 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)
}
)

更新:

错误不会出现,直到我输入成功和失败处理程序。这很好:

        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结合闭包的类型推断的一些不足造成的。您可以尝试以下方法之一:

要么不使用尾随闭包,例如

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)
})

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

 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)
}

关于ios - 对成员 Swift 3 的模糊引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41952036/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com