Xcode:错误域= DVTPlaygroundCommunicationErrorDomain代码= 1 [英] Xcode: Error Domain=DVTPlaygroundCommunicationErrorDomain Code=1

查看:120
本文介绍了Xcode:错误域= DVTPlaygroundCommunicationErrorDomain代码= 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试Swift Playground中DispatchWork项的取消,尽管在执行的最初几毫秒中有一个错误,我不确定它实际上指示了什么,也无法确定错误导致取消,而不是cancel()方法...

I'm attempting to test the cancellation of a DispatchWork item within a Swift Playground, although during the first few milliseconds of execution there's an error, which I'm not sure what it's actually indicating, nor can I tell if the error is causing the cancellation rather than the cancel() method...

func testDispatchWorkItems() {
    let queue = DispatchQueue.global(qos: .userInitiated)
    var item: DispatchWorkItem?

    // create work item

    item = DispatchWorkItem {
        for i in 0 ... 100000 {
            if item!.isCancelled { break }
            print(i)
        }
    }

    // start it

    queue.async(execute: item!)

    // after three seconds, stop it

    queue.asyncAfter(deadline: .now() + 3) {
        item?.cancel()
    }
}

testDispatchWorkItems()

 2016-10-26 11:14:33.898
 com.apple.dt.Xcode.PlaygroundStub-macosx[30685:18567692] Error
 encountered communicating with Xcode: Error
 Domain=DVTPlaygroundCommunicationErrorDomain Code=1 "Cannot send data
 because stream is closed." UserInfo={NSLocalizedDescription=Cannot
 send data because stream is closed.}

有人知道该错误表示什么吗?

Has someone got an idea what that error is indicating?

推荐答案

needsIndefiniteExecution设置为true可以忽略此警告.一旦游乐场执行比线程处理更早结束,就会发生警告.

Set needsIndefiniteExecution to true can omit this warning. The warning happens once playground execution ends earlier than thread processing.

import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true

这篇关于Xcode:错误域= DVTPlaygroundCommunicationErrorDomain代码= 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆