Search code examples
iphoneiosobjective-cgrand-central-dispatchdispatch

Get current dispatch queue?


I have a method which should support being called from any queue, and should expect to.

It runs some code in a background thread itself, and then uses dispatch_get_main_queue when it returns a value to its block argument.

I don't want it to force it onto the main queue if it wasn't when it entered the method. Is there a way to get a pointer to the current dispatch queue?


Solution

  • You do have the option of "dispatch_get_current_queue()", however the iOS 6.1 SDK defines this API with these disclaimers:

    "Recommended for debugging and logging purposes only:"

    and

    "This function is deprecated and will be removed in a future release.".

    Here's another related question with some alternatives you can consider if you want code that's future-proof.