From the course: iOS Development: Architecture

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Moving work off the main thread

Moving work off the main thread

From the course: iOS Development: Architecture

Start my 1-month free trial

Moving work off the main thread

- [Commentator] Now, let's get back to our demo app. Creating a concurrent queue is quite straightforward. The easiest way is to get one of the already available global concurrent queues. You do it by calling DispactchQueue.global Next, I specify that I want to execute my task asynchronously. We can achieve that by calling the async method. The task to be executed gets submitted as a block. So, I move all the image download logic in this block. Now, let's see the results of this refactoring. But, first we have to fix this tiny compiler problem because we are working inside a closure, we have to provide an explicit self when using our photo links. Alright, now, let's build and draw on the app. The images are downloading slowly, but the scrolling experience is not affected. If we go back to X code, we'll see that we have a warning. Our main threat checker says that our UI API was called on a background thread. Indeed, if you take a look at the code, we see that we set the image from…

Contents