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

Questions on Concurrency

I am totally lost about sharedSession and why this makes things concurrent? Please Help!!

2 Answers

sharedSession belongs to NSURLSession. NSURLSession provides an easy to use api to download things from the web. it downloads data on a background thread which is separate from the main thread.

UI (buttons, labels etc) updates take place on the main thread. if you downloaded something on the main thread, the UI would not be able to update/move/change/interact with until that process was complete

by downloading things on this background thread, it keeps the main thread free, which means the UI can update, and you can download data, all at the same time.

this is what makes NSURLSession concurrent, the fact that it works on a background thread.

+1 To add onto that, it also handles other data tasks and uploads all within the same context.

Thank you for your answers. So i guess what you guys are saying is that sharedsession is the function that allows for things to be concorrent?

yes. sharedSession and the NSURLSession class is what does all the work for you and makes everything concurrent. there is a lot of stuff that the methods of that class do that you never see. that class is what makes everything work