0

I'm using Alamofire and Swifty and am able to make my API POST and get data back successfully. However, I'm unsure of how to get the data that I'm printing and be able to return it as a string.

In the below, the println's print fine. However, when I use the same json["ticket"] as the return, I get 'JSON' is not convertible to 'Void'

let encoding = Alamofire.ParameterEncoding.URL

    // Fetch Request
    Alamofire.request(.POST, "http://api.co/?v=1", parameters: bodyParameters, encoding: encoding)
        .validate(statusCode: 200..<300)
        .responseJSON{(request, response, data, error) in

            if (error == nil)
            {
                var json =  JSON(data!)
                println(json["ticket"])
                return json["TOKEN"]
            }
            else
            {
                println("HTTP HTTP Request failed: \(error)")
            }
bdizzle
  • 419
  • 2
  • 5
  • 19

1 Answers1

1

The problem is you are returning "Dictionary" from the closure, while Closure return type is Void. So, you need to get that in a completion handler.

For better idea, you can take a look at this solution. Hope it helps!

Community
  • 1
  • 1
Sohil R. Memon
  • 9,404
  • 1
  • 31
  • 57