2016-10-21 16 views
1

プロジェクトをSwift 2.2からSwift 3.0に更新しました。それから、私はSwift 2.3に格下げされました。今、私は解決策を見つけることができないこのエラーが発生しています。なぜこのエラーが出るのか誰も知っていますか?"ケース" - 条件の変数バインディングにイニシャライザが必要

Variable binding in a condition requires an initializer

これは私が使用している機能である:

func credentials(values: [String: String], callback: Result<Credentials> ->()) { 
    guard 
     let code = values["code"] 
     else { 
      let data = try! NSJSONSerialization.dataWithJSONObject(values, options: []) 
      let string = String(data: data, encoding: NSUTF8StringEncoding) 
      return callback(.Failure(error: AuthenticationError(string: string))) 
     } 
    let clientId = self.clientId 
    Authentication(clientId: clientId, url: url) 
     .tokenExchange(withCode: code, codeVerifier: verifier, redirectURI: redirectURL.absoluteString!) 
     .start { result in 
      // error is in if-case below: 
      if case .Failure(let cause as AuthenticationError) = result, cause.description == "Unauthorized"{ 

       let error = WebAuthError.PKCENotAllowed("Please go to 'https://manage.auth0.com/#/applications/\(clientId)/settings' and set 'Token Endpoint Authentication Method' to 'None' to enable PKCE.") 
       callback(Result.Failure(error: error)) 
      } else { 
       callback(result) 
      } 
     } 
} 
+0

エラーは、関連する値「原因」をバインドされた変数として使用できないことを意味します。 'if case let'を使用してください。 – vadian

+0

@vadianあなたの助けに感謝します。私は '原因 '変数を作成するときに' let'を使っています... ''もし ''の場合は ''の後ろに ''を置くと、エラーは同じままです...おそらく私はあなたの点を得ませんでした – guijob

+0

これは私の最初の迅速なプロジェクトなので、私は慣れていない – guijob

答えて

3

たぶん

let cause = cause as AuthenticationError 

let cause as AuthenticationError 

を変更してみてください、私は同様の問題を抱えていたし、それは私のためにそれを解決しました。

関連する問題