2017-01-31 72 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 –

相關問題