3

我在 Swift 2 中有这样的代码:

let attrs = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_UTILITY, 0)
let myQueue = dispatch_queue_create("com.example.serial-queue", attrs)

这在 Swift 3 中无法编译,因为dispatch_queue_attr_make_with_qos_classanddispatch_queue_create不可用。如何使用自定义 QoS 类创建串行队列?

4

1 回答 1

7

DispatchQueue现在是 a class,您可以使用它的init(label:attributes:target:)初始化程序。这些属性现在是一个名为 的 OptionSet DispatchQueueAttributes,它具有实例.serial.qosUtility.

把它放在一起:

let myQueue = DispatchQueue(label: "com.example.serial-queue",
                            attributes: [.serial, .qosUtility])
于 2016-06-14T18:29:01.787 回答