Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are dispatch queue names in iOS meaningful for any reason other than debugging?

I'm wondering about declarations like this:

let queue = DispatchQueue(label: "com.example.imagetransform")

I was watching WWDC Concurrency with Swift 3, and the presenter mentioned in the above that the label of the queue shows in the debugger. I am wondering, apart from this, is the name meaningful or useful for referencing that queue, or do these queues follow the same scope rules as other kinds of data structures (so that the queue declaration is only meaningful within its scope).

Even if the queue declaration is only meaningful within its scope, what happens if I do this?

let queue1 = DispatchQueue(label: "com.example.imagetransform")
let queue2 = DispatchQueue(label: "com.example.imagetransform")

Are these queues actually the same so that if I first say add a job to queue1 and then add a job to queue2, queue2's job is actually on the same line as queue1's job?

like image 381
helloB Avatar asked Jul 20 '16 19:07

helloB


Video Answer


2 Answers

Are dispatch queue names in iOS meaningful for any reason other than debugging?

Their primary purpose is for debugging. You theoretically could use it for other purposes (it's accessible through the label property), but it's advisable to simply use it for diagnostic purposes.

Are these queues actually the same so that if I first say add a job to queue1 and then add a job to queue2, is queue2's job is actually on the same line as queue1's job?

No, they are distinct queues and tasks submitted to one have absolutely nothing to do with tasks submitted to the other. They just happen to have the same name, which only makes debugging a little more confusing.

Most of us would be inclined to give them names that would still capture the functional intent but make them unique to simplify debugging, e.g.:

let queue1 = DispatchQueue(label: "com.example.imagetransform.1")
let queue2 = DispatchQueue(label: "com.example.imagetransform.2")
like image 187
Rob Avatar answered Sep 28 '22 20:09

Rob


The label is just as it says: a label. It has no semantics and no influence on scope. It is purely "for your information" (which in most cases means "debugging").

like image 37
Rob Napier Avatar answered Sep 28 '22 19:09

Rob Napier