What is URLSession in Swift?

Updated May 17, 2026

Short answer

URLSession is used for network requests.

Deep explanation

It handles HTTP requests, responses, and background transfers.

Real-world example

Fetching data from REST APIs.

Common mistakes

  • Not handling errors properly.

Follow-up questions

  • What is dataTask?
  • Can URLSession run in background?

More Swift interview questions

View all →