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

Unlock the full course today

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

Solution: Load images in a collection view

Solution: Load images in a collection view

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

Start my 1-month free trial

Solution: Load images in a collection view

(upbeat music) - (Instructor)To solve this issue, we are going to start with the API helper class. So in our fetch random images here that takes a completion handler, we're going to ensure that our completion handler is being called from the main thread. So dispatchqueue.main.async and transfer our completion handler there. Next we're going to go to the custom image view class, and here we need to make sure that our image is been cached, so we're going to create an instance of Cache, let image Cache. Image cache equals to NSCache, Any Object Then inside our load image function, we're going to assign our image to nil. And you're doing so, just in case there was an image assigned before. And we are going to assign it again at the end of our code. All right, so for this code, we also need to make sure that we are assigning it from the main queue as well. Because this involves updating the UI. And just before we assign…

Contents