<!--
{
  "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/urlSession(_:dataTask:didReceive:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSURLSessionDataDelegate(im)URLSession:dataTask:didReceiveData:"
  },
  "title" : "urlSession(_:dataTask:didReceive:)"
}
-->

# urlSession(_:dataTask:didReceive:)

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

```
optional func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data)
```

## Parameters

`session`

The session containing the data task that provided data.

`dataTask`

The data task that provided data.

`data`

A data object containing the transferred data.

## Discussion

Because the data object parameter is often pieced together from a number of different data objects, whenever possible, use the [`enumerateBytes(_:)`](/documentation/Foundation/NSData/enumerateBytes(_:)) method to iterate through the data rather than using the [`bytes`](/documentation/Foundation/NSData/bytes) method (which flattens the data object into a single memory block).

This delegate method may be called more than once, and each call provides only data received since the previous call. The app is responsible for accumulating this data if needed.

---

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)