Improving performance with Concurrency
Concurrency is a complex computer science topic, not only in iOS development. A bad design can lead to crashes, race conditions, deadlocks, and lags.
But don’t worry – do you remember what we said about design patterns in this chapter’s introduction? They are here to solve our problems. So, let’s review some of the design patterns and best practices for concurrency to see what tools we can add to our toolbox.
Working with GCD
GCD is a powerful concurrency framework that enables the efficient and scalable execution of tasks. GCD provides a simple way to create queues of tasks and schedule them for execution without managing threads manually. This makes it easy to write efficient and responsive code that takes full advantage of the available system resources.
Here is an example of how to use GCD to download an image asynchronously in the background:
func downloadImage(url: URL, completion: @escaping ...