簡體   English   中英

XCode playground掛起異步代碼

[英]XCode playground hangs on async code

我正在嘗試使用Alamofire在XCode 7.3操場中創建異步請求。 我已經包含了兩個額外的語句 - 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

我還將游樂場執行模式設置為手動。

第一次,一切正常,打印響應,操場完成執行。

但是,如果我第二次運行它,它會掛起並且不會打印任何輸出(甚至沒有“開始請求”)。 我必須重新啟動XCode以使其再次工作。

您可以嘗試刪除:

XCPlaygroundPage.currentPage.finishExecution()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM