2017-01-31 6 views
5

私のプロジェクトをSwift 2.3からSwift 3に移行しています。メンバーSwiftへのあいまいな参照3

OAuthSwiftを使用して、OAuthで使用されている関数です。私は

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:私は成功とfaliure handelrsを入力unitil

エラーは表示されません。これは正常に準拠します:

 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 –

関連する問題