Alamofire的回应总是零

时间:2017-01-11 00:52:09

标签: ios swift3 alamofire

我尝试使用Alamofire 4和swift 3编写REST客户端的基本示例,但无论我尝试访问哪种服务,响应总是为零。

我错过了任何配置吗?

这是我的代码:

private void CreateRadioButton()
{
    int rbCount = 40;
        int numberOfColumns = 8;
        var radioButtons = new RadioButton[rbCount];
        int y = 20;
        for (int i = 0; i < rbCount; ++i)
        {
            radioButtons[i] = new RadioButton();
            radioButtons[i].Text = Convert.ToString(i);
            if (i%numberOfColumns==0)  y += 20; 
            var x = 514 + i%numberOfColumns * 37;
            radioButtons[i].Location = new Point(x, y);
            radioButtons[i].Size = new Size(37, 17);
            this.Controls.Add(radioButtons[i]);
        }
}

Podfile

override func viewDidLoad() {
    super.viewDidLoad()

    Alamofire.request("https://httpbin.org/get").responseJSON { response in
        print(response.request)  // original URL request
        print(response.response) // HTTP URL response
        print(response.data)     // server data
        print(response.result)   // result of response serialization

        if let JSON = response.result.value {
            print("JSON: \(JSON)")
        }
    }
}

的Info.plist

Info.plist

1 个答案:

答案 0 :(得分:0)

只要Alamofire使用异步请求,代码的下一部分就会在请求之前执行。

因此,为了确保执行顺序,依赖于响应的代码必须进入闭包。