Retrieving data from the web is something that you will do often as an iOS professional. You won't just fetch data from a web service; you'll also send data back to it. For example, you might make an HTTP POST request to log in a user or to update their information. Over time, iOS has evolved quite a bit in the web requests department, making it easier, simpler, and more consistent to use the web in apps, and we're currently in a pretty good spot with the URLSession class.
The URLSession class makes asynchronous web requests on your behalf. This means that iOS loads data from the internet on a background thread, ensuring that the user interface remains responsive throughout the duration of the entire request. If the request is performed synchronously, the user interface will be unresponsive for the duration of the network request because a thread can only do one thing at a time, so if it's waiting for a response from the network, it can't respond to touches or other user input.
If your user has a slow internet connection, a request could take several seconds. You don't want your interface to freeze for several seconds. Even a couple of milliseconds will create a noticeable drop in its responsiveness and frame rate. This can be easily avoided using URLSession to perform asynchronous network requests.
First, we will look at basic network requests in a playground. You can create a new playground or use the one provided in this book's code bundle. After you've seen the basics of URLSession, we'll implement a way to fetch movies from an open source movie database and finally put this implementation to use in the FamilyMovies app.