From the course: iOS Development: Threading and Grand Central Dispatch

Unlock the full course today

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

Solution: Optimizing the collection view

Solution: Optimizing the collection view

From the course: iOS Development: Threading and Grand Central Dispatch

Start my 1-month free trial

Solution: Optimizing the collection view

(upbeat music) - [Instructor] For our solution, open the MainViewController, go to the CellForItemAt function. You're going to ensure that our image is downloaded from a background queue. Then change our if statement to a guard statement. Let's just copy this here. Don't forget the else, else we return. Now once we have the image, we need to update it on the main thread or from the main thread. So we call DispatchQueue.main.async, and then we update the cell from there. Okay, let's now run our code. You will notice that the app has started up much more faster than earlier and also the UI is scrolling much more smoothly.

Contents