XCode playground挂起异步代码

时间:2016-04-09 14:43:13

标签: xcode swift alamofire swift-playground

我尝试使用Alamofire在XCode 7.3游乐场内制作异步请求。我已经包含了另外两个声明 - needsIndefiniteExecution = truefinishExecution(),如此答案中所述:https://stackoverflow.com/a/33536290/603268

import Foundation
import Alamofire
import XCPlayground

XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

print("Before request")

Alamofire
    .request(.GET, "http://jsonplaceholder.typicode.com/users")
    .responseString { res in
        print(res)
        XCPlaygroundPage.currentPage.finishExecution()
    }
    //.resume() - adding this did not help

我还将游乐场执行模式设置为手动。

第一次,一切正常,打印响应,操场完成执行。

但是,如果我第二次运行它,它会挂起并且不会打印任何输出(即使没有"开始请求")。我必须重新启动XCode以使其再次工作。

1 个答案:

答案 0 :(得分:0)

您可以尝试删除:

XCPlaygroundPage.currentPage.finishExecution()
相关问题