问题
I am running into a strange issue where Alamofire.request(.GET) statement in my playground gets executed after some delay in the playground
Setup: I followed the following link to import Alamofire framework to test networking requests in xcode playground.
This is the code I have in my playground. And when I look at the logs of my webserver the logs get updated after almost ~few minutes delay. I have verfied that it is not the log process that is causing delay. Making same http request using curl and from browser, I see logs getting updated almost instantly.
    import UIKit
    import Alamofire
    Alamofire.request(.GET, "http://localhost:5010/asdf")
        .responseJSON { response in
            print ("Hello there in playground")
            print(response.request)  // original URL request
            print(response.response) // URL response
            print(response.data)     // server data
            print(response.result)   // result of response serialization
            if let JSON = response.result.value {
                print("JSON: \(JSON)")
            }
    }
    回答1:
Playground behavior for time-delayed things like network requests is … unpredictable at best.
Try letting the playground know it should wait for your network request:
import UIKit
import Alamofire
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
Alamofire.request(.GET, "http://localhost:5010/asdf")
    .responseJSON { response in
        print ("Hello there in playground")
        print(response.request)  // original URL request
        print(response.response) // URL response
        print(response.data)     // server data
        print(response.result)   // result of response serialization
        if let JSON = response.result.value {
            print("JSON: \(JSON)")
        }
        XCPlaygroundPage.currentPage.finishExecution()
    }
    来源:https://stackoverflow.com/questions/33535968/delay-in-making-http-requests-using-alamofire-in-playground