在Swift Playground中查看GET请求结果

时间:2016-03-30 02:28:01

标签: swift rest alamofire swift-playground

我们正在尝试使用Playground测试Alomofire GET请求。它正在工作但我们无法在Playground中看到请求返回的JSON。你怎么能这样做?注意单击屏幕截图中的右箭头不会显示任何JSON。

游乐场:

enter image description here

request's JSON回复:

{
  "userId": 1,
  "id": 2,
  "title": "qui est esse",
  "body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
}

1 个答案:

答案 0 :(得分:1)

在请求完成之前,您的游乐场已经结束。通过设置needsIndefiniteExecution = true

无限期暂停
import UIKit
import SwiftyJSON
import Alamofire
import XCPlayground

Alamofire.request(.GET, "http://jsonplaceholder.typicode.com/posts/2")
    .responseJSON { response in
        let json = JSON(data: response.data!)
        print(json)
    }

XCPlaygroundPage.currentPage.needsIndefiniteExecution = true