Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'DispatchQueue.Attributes' has no member 'serial'

I have converted existing Swift2.3 code to Swift3.0 using Xcode8 beta4. Xcode automatically convert syntax to Swift3.0, but it not able to create serial dispatch queue.

private let serialQueue = DispatchQueue(label: "identifier", qos: DispatchQueue.Attributes.serial)

like image 428
technerd Avatar asked Sep 06 '16 09:09

technerd


People also ask

Is DispatchQueue serial?

By default, DispatchQueue is a serial queue. E.g. As you can see in the Output, the code is executed in the order it was defined, even though we used the async( ) function, the first thread took 3 seconds for completion and after that, the second thread was executed which took another second to complete.

Is DispatchQueue main concurrent?

In general, dispatch queues will only perform one task at a time in a first-in, first-out kind of fashion. They can, however, be configured to schedule work concurrently. The main dispatch queue is a queue that runs one task at a time.

What is the DispatchQueue in Swift?

A dispatch queue that is bound to the app's main thread and executes tasks serially on that thread. A dispatch queue that executes tasks concurrently using threads from the global thread pool. A dispatch queue that executes tasks serially in first-in, first-out (FIFO) order.

What do we use DispatchQueue for?

A dispatch queue executes tasks serially or concurrently on its associated thread. If you want to read more about dispatch queues, I encourage you to read my article Concurrent vs Serial DispatchQueue: Concurrency in Swift explained.


1 Answers

There is not .serial attribute anymore, but dispatch queues are by default serial, unless you specify the .concurrent attribute:

let serialQueue = DispatchQueue(label: "label")
let concurrentQueue = DispatchQueue(label: "label", attributes: .concurrent)

Source: How to create a serial DispatchQueue in swift 3 with Xcode 8 beta 4? in the Apple Developer Forum.

like image 78
Martin R Avatar answered Oct 20 '22 05:10

Martin R