Search code examples
iosswiftalamofire

Must I wait for Alamofire to finish post request or is it all asynchronous


I wonder how Alamofire run asynchronous?

When a user taps a button in my app this gets fired:

Alamofire.request(.POST, "www.someaddress", parameters: parameters, headers: headers, encoding: .JSON)
            .responseJSON() { response in
                //Do nothing..
        }

Is the user still able to go back to the previous VC or must I wait for the Alamofire Post request to return?


Solution

  • You dont need to care about that, Alamofire runs all request asynchronous.

    Check out the docu here:

    https://github.com/Alamofire/Alamofire/blob/master/README.md

    Networking in Alamofire is done asynchronously. Asynchronous programming may be a source of frustration to programmers unfamiliar with the concept, but there are very good reasons for doing it this way.

    And all requests still run automatically on an background-thread too. So you dont need to wait till the request is finished (No UI Interaction will be blocked)