Grand Central Dispatch for concurrency

13154
0

Grand Central Dispatch (GCD) manages concurrent code execution with dispatch queues. The main queue handles UI updates—I use DispatchQueue.main.async to return to main thread after background work. Global queues provide concurrent background execution with different quality of service levels: .userInteractive, .userInitiated, .utility, and .background. Custom queues offer fine-grained control over concurrency. Dispatch groups coordinate multiple async tasks, waiting for all to complete with group.notify(). Semaphores limit concurrent access to resources. For modern Swift, async/await is preferred, but GCD remains essential for legacy code and certain use cases like debouncing and rate limiting.