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?
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 toqueue2
, isqueue2
's job is actually on the same line asqueue1
'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")
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").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With