问题
I am quite fond of the threadDictionary
property in NSThread
: very handy to store things with per-thread ownership.
Is there an equivalent dictionary for a GCD queue?
回答1:
You might want to look into dispatch_set_context/dispatch_get_context
. Documentation here and here. You have to manage the context but it might be what you're looking for.
回答2:
If you can target iOS 5 and above, you can use dispatch_queue_get[set]_specific()
which allows you to add dictionary-style (i.e. keyed) values to a queue. I can't find the document pages on them, strangely enough, but they are commented in queue.h
来源:https://stackoverflow.com/questions/11962850/is-there-a-queue-dictionary-for-a-gcd-queue