Contact
← Back to Topics

URLSession

API for downloading and uploading data with HTTP in iOS and macOS applications.

About URLSession

URLSession is Apple's modern networking API for handling HTTP/HTTPS requests in iOS and macOS applications.

Key Features

  • Background transfers
  • Download/upload tasks
  • Data tasks
  • WebSocket support
  • Authentication handling

Code Example

// Basic URLSession request
let url = URL(string: "https://api.example.com/data")!
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
    if let data = data {
        let string = String(data: data, encoding: .utf8)
        print(string ?? "No data")
    }
}
task.resume()