2017-01-31 34 views
5

我正在将我的项目从Swift 2.3迁移到Swift 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 

错误状态

暧昧参考成员的授权(withCallbackURL得到一个错误:范围:状态:参数:头:成功:失败:)'

这是Swi的工作代码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:

错误不会出现unitil I型成功,faliure handelrs。这符合罚款:

 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 
    } 

所以请引导我谢谢。

回答

7

我认为这个问题是由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) 
} 
+0

不使用拖尾关闭的技巧。但我不明白为什么! –

+0

这是一个缺点,请看这里: https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20160704/002370.html –

相关问题