Customizing URLSessionConfiguration properties

So far, we have used a preconfigured catch-all URLSession instance, called shared. It's great; it not only does a lot of stuff with a single word of code, but it also got us through the first few pages of this chapter without us having to worry about configuring it, so allowing us to focus on URLSession's basic way of working (and a lecture about separation of concerns).

So, what might we wish to change about the session that will require us to configure our own instead of using shared?

There are many things, and we won't cover all of them here, but the most common include:

  • Adding content type headers
  • Adding authorization key headers
  • Setting a cache policy
  • Setting timeout intervals for the request ...

Get Mastering macOS Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.