Question

I know that GCD's dispatch_get_current_queue has been deprecated, and it is an anti-pattern to use it for callbacks anyway, but is -[NSOperationQueue currentQueue] reliable to use, or does it suffer from the same problems that GCD's dispatch_get_current_queue has? (I just want it so I can assert that I'm on the proper queue when my operation executes.)

Was it helpful?

Solution

dispatch_get_current_queue was not deprecated because it's unreliable. It's deprecated because nearly all uses of it other than assertions are a bad idea, and because there can be more than one simultaneous current queue.

NSOperationQueue does not support target queues or synchronous execution, which are the two reasons the latter issue exists in dispatch, so it should be fine to use for assertions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top