[英]XCode playground hangs on async code
I'm trying to make an async request inside XCode 7.3 playground, using Alamofire. 我正在尝试使用Alamofire在XCode 7.3操场中创建异步请求。 I've included two additional statements - needsIndefiniteExecution = true
and finishExecution()
as described in this answer: https://stackoverflow.com/a/33536290/603268 . 我已经包含了两个额外的语句 - needsIndefiniteExecution = true
和finishExecution()
,如本答案所述: https : finishExecution()
。
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
I've also set the playground execution mode to manual. 我还将游乐场执行模式设置为手动。
The first time, everything works fine, the response is printed and the playground finishes execution. 第一次,一切正常,打印响应,操场完成执行。
However, if I run it second time, it hangs and does not print any output (even no "Begin request"). 但是,如果我第二次运行它,它会挂起并且不会打印任何输出(甚至没有“开始请求”)。 I have to restart XCode to make it work again. 我必须重新启动XCode以使其再次工作。
您可以尝试删除:
XCPlaygroundPage.currentPage.finishExecution()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.