Alamofire.request( .GET, "http://localhost:9080/feed", parameters: [:]) .responseJSON { response in guard response.result.isSuccess else { print("Error while fetching: (response.result.error)") return } 

Error: Code = -1004 "Could not connect to the server."

I launch the server on Swift, the server is running, the browser gives test data along the path " http: // localhost: 9080 / feed "

 AllowArbitraryLoads = Yes response.result.value = nil 

    1 answer 1

    The following things helped:

    executed sudo ifconfig. It has been shown that I have written in the settings

    inet6 fe80 :: 61e: 64ff: fef8: 4c2e% en1 prefixlen 64 scopeid 0x5 inet 192.168.0.20 netmask 0xffffff00 broadcast 192.168.0.255

    Therefore, I wrote 192.168.0.20 (instead of localhost or 127.0.0.1)