"如果是案例" - 条件中的变量绑定需要初始化程序

时间:2016-10-21 20:50:36

标签: swift auth0

我将我的项目从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)
            }
        }
}

1 个答案:

答案 0 :(得分:3)

也许尝试更改

let cause as AuthenticationError

let cause = cause as AuthenticationError

我遇到了类似的问题,并为我解决了这个问题。