<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSession/data(from:delegate:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:So12NSURLSessionC10FoundationE4data4from8delegateAC4DataV_So13NSURLResponseCtAC3URLV_So0A12TaskDelegate_pSgtYaKF"
  },
  "title" : "data(from:delegate:)"
}
-->

# data(from:delegate:)

Retrieves the contents of a URL and delivers the data asynchronously.

```
func data(from url: URL, delegate: (any URLSessionTaskDelegate)? = nil) async throws -> (Data, URLResponse)
```

## Parameters

`url`

The URL to retrieve.

`delegate`

A delegate that receives life cycle and authentication challenge callbacks as the transfer progresses.

## Return Value

An asynchronously-delivered tuple that contains the URL contents as a [`Data`](/documentation/Foundation/Data) instance, and a [`URLResponse`](/documentation/Foundation/URLResponse).

## Discussion

Use this method to wait until the session finishes transferring data and receive it in a single [`Data`](/documentation/Foundation/Data) instance. To process the bytes as the session receives them, use [`bytes(from:delegate:)`](/documentation/Foundation/URLSession/bytes(from:delegate:)).

---

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)