Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Alamofire response status code

How can I get status code from the Alamofire response?

In the latest version I can use validate but I need to check what the status code is.

Code:

Alamofire.request(.GET, "http://example.com/url")
         .responseJSON { response in

         }
like image 812
Mirza Delic Avatar asked Dec 04 '25 11:12

Mirza Delic


1 Answers

This works (after @MirzaDelic pointed out my mistake):

Alamofire.request(.get, "http://www.google.com")
    .responseJSON { response in
        if response.response.statusCode == 404 {
            // do something
        } else {
            // do something else
        }
}
like image 192
damianesteban Avatar answered Dec 09 '25 14:12

damianesteban



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!