简体   繁体   English

XCode playground挂起异步代码

[英]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 = truefinishExecution() ,如本答案所述: httpsfinishExecution()

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.

相关问题 每当我在操场上写几行代码时,XCode都会挂起 - XCode hangs every time when i write few lines of code in playground 代码将基于Xcode构建,但不能在Playground上运行。 为什么? - Code will build on Xcode but no run on Playground. Why? Xcode Playground崩溃并带有非swift代码 - Xcode Playground crashing with non-swift code Xcode Playground使用简单的UITableViewController代码崩溃 - Xcode Playground crashes with a simple UITableViewController code Swift 2.0代码适用于Xcode,但不适用于Playground - Swift 2.0 code works in Xcode but not in Playground Xcode游乐场 - Xcode Playground 如何在使用cocoapods时将项目代码暴露给Xcode游乐场? - How to expose your project code to a Xcode playground when using cocoapods? 为什么我的Swift代码在操场上可以工作,而在Xcode项目中却不能工作? - Why does my Swift code work in the playground but not in the Xcode project? Xcode playground 卡在“Running playground”或“Launching simulator”上,无法运行代码,怎么办? - Xcode playground gets stuck on 'Running playground' or 'Launching simulator' and won't run the code, what to do? 文本文件到字符串数组代码在Playground中有效,但在Xcode项目中无效 - Text file to Array of Strings code is working in Playground but not in Xcode project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM