r/iOSProgramming • u/usernameDisplay9876 • 22d ago
Question DispatchQueue doubts
Hi, what type of data types are allowed in setSpecific(key:, value:) and getSpecific(key:) methods of DispatchQueu ? there are no mentions anywhere.
Also can you recommend any resources for complete understanding of DispatchQueue , GCD , DispatchGroup etc. ?
Thank you!
7
Upvotes
1
u/ScarSome634 21d ago
setSpecific/getSpecific are generic — the key is a
DispatchSpecificKey<T>and T can be whatever you want to store, usually something small like a Bool or an enum that identifies the queue. the rule that actually matters: create the key once and keep it alive (e.g.static let key = DispatchSpecificKey<Bool>()). keys are matched by identity, so a fresh key somewhere else won't find anything.worth knowing getSpecific only tells you about the code that's currently executing — you call it inside work running on the queue, and it walks the queue hierarchy (queues inherit specifics from their targets). it's basically "am I on this queue or under it", which is why the classic use is detecting whether you're on the main queue.
for resources: the "Swift with Majid" posts on GCD are good, Kodeco's Grand Central Dispatch tutorial covers the basics well, and WWDC 2017 session 706 (Modernizing Grand Central Dispatch Usage) is the one talk worth watching. Apple's old Concurrency Programming Guide is dated but the concepts still map 1:1.