Networking with URLSession

Learn how to use URLSession, Apple's networking API, including when and how to use data, download and upload tasks, with or without a custom session delegate, and how the system manages background sessions. Keep your users' data safe with authentication and App Transport Security, and pick up tips for networking architecture, testing and metrics. Updated for iOS 11 and Swift 4. By Audrey Tam.

Leave a rating/review
Save for later
Comments
Share
01
Toggle description

Find out what’s covered in our video course Networking with URLSession.

HTTP 101 11:54
Toggle description

Learn some HTTP basics to make the most of URLSession, and discover the easy way to create URL objects from Strings.

URLSession 15:51
Toggle description

The URLSession API has many moving parts: learn about URLSessionConfigurations, URLSessionTasks and delegates, and how they fit together.

Toggle description

Learn about REST and JSON, then create a URLSession data task that makes a GET request on a REST API, and parses the JSON URLResponse.

05
Toggle description

Learn about URLRequest and HTTP headers, then create a URLSessionDataTask to POST to a REST API. Also build an Alamofire-inspired PostRouter to create URLRequests.

Toggle description

Learn about URLSessionDownloadTask and URLSessionUploadTask to save results to a file, or upload a data object or a file.

Toggle description

Download and upload tasks can run in a background session. Find out how the system handles this, and learn some advice and tips for long-running tasks.

Toggle description

Learn how to handle authentication and cookies.

ATS 25:49
Toggle description

Learn what your app needs to do to support Apple's requirement for App Transport Security.

Toggle description

URLSession is an OperationQueue, and delegate and completion methods run on another OperationQueue: learn how to customize the delegate queue.

Architecture 15:24
Toggle description

MVC shouldn't mean Massive View Controller: learn some ways to move networking code out of the view controller, and how to wrap a session task in an Operation.

Toggle description

Writing unit tests is A Good Thing: learn how to test asynchronous network code. And find out how to access URLSessionTaskMetrics transaction data.

Conclusion 4:03
Toggle description

Review what you've learned in this video course, and get a TODO list for discussions with your back-end server team.