Beginning Networking with URLSession

Sep 13 2022 · Swift 5.6, iOS 15, Xcode 13.4.1

Part 1: Introduction to URLSession & Concurrency

01. Introduction

Episode complete

Play next episode

About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Next episode: 02. Introduction to Modern Concurrency

Notes: 01. Introduction

URLSession - Apple Developer

Transcript: 01. Introduction Hello hello, and welcome to the Beginning Networking with URLSession course. I am Felipe and I'll be your instructor as we dive into the wonderful world of networking. You see I've been building my own apps and projects and while they're pretty cool and fun to use, they all live in their own little bubble with no way to connect or interact with the internet at all. I have so many ideas, as you probably do as well, on how to download data from the internet, upload data to some server, or web service, and enhance the overall interactivity and quality of life. In this course I'll take you on the internet and bring your apps to a whole new level. Networking is a deep topic with lots and lots of things to consider. There are a variety of network protocols and proxies with edge cases for each of them. In order to provide a seamless experience you need to account for all of them. Thankfully Apple does this for us in their network framework. The framework exposes a lot of the moving parts which handles network communication, but what if you just want to download a cute cat picture from the internet? The last thing you wanna do is spend hours of your time making your way through pages of technical documentation for a complicated framework. I mean, you're just trying to get a picture of a cat after all. Apple has come to the rescue with URLSession, an API built on top of the networking framework that handles all of the low level details of communicating across the network while allowing you control of the experience. Prior to URLSession we had to use URLConnection, and while it got the job done, it was clunky to manage, doing anything off the beaten path meant writing your threading code, and the API itself was a bit clunky and unwieldy. It was like trying to write an email with a cat on your keyboard, you just couldn't do it. And while you could try, there's likely gonna be a lot of typos involved. Developers responded to this by creating their own solutions. Back in the old days most apps included libraries such as Alamofire, and AFNetworking to take the sting out of NS URLConnection. Apple took notice however. As of IOS seven, there's URLSession. What used to be a painful experience for making even simple requests became an incredibly easy and intuitive API. URLSession is a high level framework that sits on top of the Apple networking stack. This stack itself is highly optimized and designed to work on a variety of network types. If you were to write your own networking library you'd need to account for all of these networks as well as the security that comes with accessing them. By using URLSession you get all these optimizations for free. Better yet, you don't need to include any unnecessary dependencies into your app to get these features. URLSession can be thought of as a tab in your browser. For instance, when you got to a webpage the browser will make a series of requests to fetch all of the assets that contribute to that page. Of course you'll quickly find that URLSession allows you to more than fetch data. URLSession comes with a variety of tasks for different jobs. Another great feature of URLSession is that you can customize each session based on how you need it to work. For instance you can have one session to download high priority images while another session runs in the background to download archived images. This course is broken into two parts. Part one will teach you about concurrency and some of the basics of working with URLSession. Part two covers topics such as downloading data, caching policies, grouping requests, and pausing, canceling, and resuming downloads. You'll see how URLSession works with the modern concurrency features of Swift, all while building a Swift UI application. Before you can really leverage URLSession you need to have a good understanding of the Swift language. This course uses Swift 5.6 on X code 13. If your knowledge is out of date or you just need a refresher, definitely check out our Programming in Swift course. You'll also need to have a basic understanding of concurrency. Concurrency is a challenging topic, but it's critical when working over the network. As an example, when you're downloading files over the internet you don't want the entire user interface to be frozen. Instead you wanna download your data in the background. This course does provide a simple refresher, but for a deep dive, check out our course on concurrency in this learning path. This course is provided with your subscription, so definitely take a look if you are new to concurrency. A big thank you goes to Brian Mogley, who was the instructor on the previous version of this course. Okay, time for the show to start. Let's dive into the world of URLSession by first reviewing concurrency.