0

I'm trying to do a simple GET-Request with Alamofire. My code looks like this:

import Alamofire

let request = AF.request("https://httpbin.org/get", method: .get)
request.responseJSON { (data) in
    print(data)
}

print("done")

Problem is that I don't get any data back. The program compiles and runs properly ("done" is printed without an exception being thrown). What am I missing?

I'm building a command line application, no SwiftUI involved here.

Timo
  • 186
  • 1
  • 13
  • 2
    Because the call is async, `print(data)` will be called AFTER `print("done")`. But, since it's a command line application, the app should finished running before `print(data)` is called. You need to keep the command line "alive". – Larme Sep 07 '21 at 11:53
  • @Larme you beat me by one minute, I was just going to say that – gtxtreme Sep 07 '21 at 11:54
  • @Larme yes, it does, thanks a lot! Didn't have that in mind, now that you say it, the problem actually becomes pretty obvious :D – Timo Sep 07 '21 at 17:08

0 Answers0