Technical requirements
All the code for this chapter can be found in this book’s GitHub repository at https://github.com/PacktPublishing/Swift-Cookbook-Third-Edition/tree/main/Chapter%206.
Using Dispatch queues for concurrency
We live in a multicore computing world. Multicore processors are found in everything, from our laptops and mobile phones to our watches. With these multiple cores comes the ability to work in parallel. These concurrent streams of work are known as threads, and programming in a multithreaded way enables your code to make the best use of the processor’s cores. Deciding how and when to create new threads and manage the available resources is a complex task, so Apple has built a framework to do the hard work for us. It is called Grand Central Dispatch, or GCD.
GCD handles thread maintenance and monitors the available resources while providing a simple, queue-based interface for getting concurrent work done. With the open sourcing of Swift,...