Cocoa 默认情况下,DispatchQueue是.serial还是.concurrent?

Cocoa 默认情况下,DispatchQueue是.serial还是.concurrent?,cocoa,grand-central-dispatch,Cocoa,Grand Central Dispatch,这就是问题所在,直截了当地说 let serial = DispatchQueue(label: "serial", attributes: .serial) let concurrent = DispatchQueue(label: "concurrent", attributes: .concurrent) let q = DispatchQueue(label: "q") 我看不到我可以在q上检查的任何属性会告诉我 在操场上运行PlaygroundPage.current.needsIn

这就是问题所在,直截了当地说

let serial = DispatchQueue(label: "serial", attributes: .serial)
let concurrent = DispatchQueue(label: "concurrent", attributes: .concurrent)
let q = DispatchQueue(label: "q")
我看不到我可以在
q
上检查的任何属性会告诉我

在操场上运行
PlaygroundPage.current.needsIndefiniteExecution=true
会显示串行行为,但我不想依赖操场(有点像异步的janky)或未记录的行为


任何人都可以提供一个带有文档链接的硬答案吗?

在Swift 3之前,默认的调度队列类型是串行的–of
dispatch\u queue\u create
将生成一个串行队列,我认为没有理由更改默认队列类型。尽管不幸的是,我在
DispatchQueue
上找不到任何可以证实这一点的文档

然而,调查显示,事实仍然如此:

public convenience init(
    label: String,
    attributes: DispatchQueueAttributes = .serial, 
    target: DispatchQueue? = nil)
{
    ...
}

虽然我总是喜欢显式地指定属性,但为了使代码更清晰并防止这种混淆。

UPD Swift 5

@Hamish的答案是正确的:默认情况下,新的DispatchQueue是串行的。 虽然源代码中属性的默认值不再像以前那样指定“.serial”:

public convenience init(
        label: String,
        qos: DispatchQoS = .unspecified,
        attributes: Attributes = [],
        autoreleaseFrequency: AutoreleaseFrequency = .inherit,
        target: DispatchQueue? = nil)
值得注意的是,属性值集具有
.concurrent
选项,但不再具有
.serial
选项。
同样,默认情况下是串行的,如果在属性数组中明确指定,则是并发的。

源代码链接非常棒,谢谢。当我在xcode中单击cmd+方法名时,我没有看到默认的param实现。@SimplGy很乐意帮助:)