Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Photo Browser iPhone App Connecting to an API using OAuth Showing Photos in a Collection View

Tushig Ochirkhuyag
Tushig Ochirkhuyag
7,226 Points

Difference between 2 ways of downloading images

In blogreader project, we used the following approach to get the image from the network:
NSData * imageData = [[NSData alloc] initWithContentsOfURL:url]; UIImage *image = [[UIImage alloc] initWithData:imageData];

On the other hand, in the Photo Bomber project we're using NSURLSession to download the image.

Could we not have constructed the image from the data in photo Bomber? the same thing we did for blogreader.

Thanks!

1 Answer

Stone Preston
Stone Preston
42,016 Points

the method used in Photo Bombers gets the image in a background thread, whereas the way you mentioned up above is running on the main thread. its better to do it in another thread. if you do it on the main thread you have to wait for the download to complete each time before other stuff can happen