<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSessionDataDelegate",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSURLSessionDataDelegate"
  },
  "title" : "URLSessionDataDelegate"
}
-->

# URLSessionDataDelegate

A protocol that defines methods that URL session instances call on their delegates to handle task-level events specific to data and upload tasks.

```
protocol URLSessionDataDelegate : URLSessionTaskDelegate
```

## Overview

Your session delegate should also implement the methods in the [`URLSessionTaskDelegate`](/documentation/Foundation/URLSessionTaskDelegate) protocol to handle task-level events that are common to all task types, and methods in the [`URLSessionDelegate`](/documentation/Foundation/URLSessionDelegate) protocol to handle session-level events.

> Note:
> A ``doc://com.apple.foundation/documentation/Foundation/URLSession`` object need not have a delegate. If no delegate is assigned, when you create tasks in that session, you must provide a completion handler block to obtain the data.
> 
> Completion handler blocks are primarily intended as an alternative to using a custom delegate. If you create a task using a method that takes a completion handler block, the delegate methods for response and data delivery are not called.

## Topics

### Handling task life cycle changes

[`urlSession(_:dataTask:didReceive:completionHandler:)`](/documentation/Foundation/URLSessionDataDelegate/urlSession(_:dataTask:didReceive:completionHandler:))

Tells the delegate that the data task received the initial reply (headers) from the server.

[`URLSession.ResponseDisposition`](/documentation/Foundation/URLSession/ResponseDisposition)

Constants indicating how a data or upload session should proceed after receiving the initial headers.

[`urlSession(_:dataTask:didBecome:)`](/documentation/Foundation/URLSessionDataDelegate/urlSession(_:dataTask:didBecome:)-60op5)

Tells the delegate that the data task was changed to a download task.

[`urlSession(_:dataTask:didBecome:)`](/documentation/Foundation/URLSessionDataDelegate/urlSession(_:dataTask:didBecome:)-7nqzu)

Tells the delegate that the data task was changed to a stream task.

### Receiving data

[`urlSession(_:dataTask:didReceive:)`](/documentation/Foundation/URLSessionDataDelegate/urlSession(_:dataTask:didReceive:))

Tells the delegate that the data task has received some of the expected data.

### Handling caching

[`urlSession(_:dataTask:willCacheResponse:completionHandler:)`](/documentation/Foundation/URLSessionDataDelegate/urlSession(_:dataTask:willCacheResponse:completionHandler:))

Asks the delegate whether the data (or upload) task should store the response in the cache.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)