12.1 · Sessions, configurations, tasks, delegates and background transfers

URLSession is the foundation under every Apple networking stack. Most surprises come from three facts: configuration is fixed at creation, an HTTP error is not a Swift error, and a session retains its delegate.

Mental model. A session is a policy object (timeouts, caches, cookies, connectivity). Tasks are the individual requests that run under it.

Sessions and tasks

Configurations, defaults and what a request returns.

  1. What do the URLSession configurations control, and how do default, ephemeral and background sessions differ? 12.1.1 · L2
    A URLSession is created from a URLSessionConfiguration that fixes its behaviour: timeouts, cache and cookie storage, credential storage, cellular and…
  2. How do you make a request with URLSession, and why is a 404 not an error? 12.1.2 · L1
    The modern call is async: let (data, response) = try await session.data(for: request) (also data(from:), upload(for:from:) and download(for:), which writes to…

More in Networking