XCode游乐场挂起异步代码



我正试图使用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

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

第一次,一切都很好,反应被打印出来,操场完成了执行。

但是,如果我第二次运行它,它将挂起并且不打印任何输出(甚至没有"Begin请求")。我必须重新启动XCode才能使其再次工作。

您可以尝试删除:

XCPlaygroundPage.currentPage.finishExecution()

最新更新