JWT'DecodeResult'没有名为'Success'的成员

时间:2015-09-10 20:27:26

标签: ios swift jwt

我尝试使用Swift JWT pod解码JWT令牌。

// Get and decode the response
    var response = NSURLConnection.sendSynchronousRequest(request, returningResponse: AutoreleasingUnsafeMutablePointer<NSURLResponse?>(), error: NSErrorPointer())
    let responseContent = NSString(data:response!, encoding:NSUTF8StringEncoding)

    let decoded = JWT.decode(responseContent! as String, .HS256(secret))

    println(decoded.Success)

此代码出错:

'DecodeResult' does not have a member named 'Success'

看起来DecodedResult有一个Enumhttps://github.com/kylef/JSONWebToken.swift/blob/master/JWT/Decode.swift#L50

如何在那里访问有效载荷?

1 个答案:

答案 0 :(得分:0)

您需要使用开关来提取枚举的关联值。

switch decoded {
case .Success(let header, let payload, let signature, let signatureInput):
    // do something with the values
case .Failure(let invalidToken):
    // handle the failure
}