Created
January 11, 2012 20:35
-
-
Save jakemarsh/1596622 to your computer and use it in GitHub Desktop.
Interview Question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There is no right answer, just want to get an idea how you would attack the problem. | |
You have a UITableView that displays images from a web service, you want to make sure it loads those images in a performant, memory conscious way, how would you do it? |
Or just to use UIImageView+WebCache class (from SDWebImage framework) and do it with one line of code (3min with implementing framework) :)
- Have some sort of queue to download images
- Draw the images when they are ready and you aren't scrolling
- Cache the images either on disk or in memory
Questions
- Are these images that need to be cached? Or will they just be displayed once? You wouldn't want to have to reload the image from a URL just because you've scrolled up and down a page
- Are the images going to change on the server? Or how will you know when to invalidate your cache?
Yep, UIImageView+WebCache can do the job too :)
probably use NSOperation rather than libdispatch, as you want the ability to cancel an image download if that image scrolls off screen. Once the image has been downloaded, it would make sense to cache them/store them in an object so that if the user is scrolling up and down we don't have to re-download stuff.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write a custom NSOperation to download the image for each table view cell, as one scrolls the code should cancel the cell operations that are not finished downloading and are off screen. Thats the general idea :)