<!--
{
  "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/bytes(from:delegate:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:So12NSURLSessionC10FoundationE5bytes4from8delegateAbCE10AsyncBytesV_So13NSURLResponseCtAC3URLV_So0A12TaskDelegate_pSgtYaKF"
  },
  "title" : "bytes(from:delegate:)"
}
-->

# bytes(from:delegate:)

Retrieves the contents of a given URL and delivers an asynchronous sequence of bytes.

```
func bytes(from url: URL, delegate: (any URLSessionTaskDelegate)? = nil) async throws -> (URLSession.AsyncBytes, 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 a [`URLSession.AsyncBytes`](/documentation/Foundation/URLSession/AsyncBytes) sequence to iterate over, and a [`URLResponse`](/documentation/Foundation/URLResponse).

## Discussion

Use this method when you want to process the bytes while the transfer is underway. You can use a `for`-`await`-`in` loop to handle each byte. For textual data, use the [`URLSession.AsyncBytes`](/documentation/Foundation/URLSession/AsyncBytes) properties <doc://com.apple.documentation/documentation/Swift/AsyncSequence/characters>, <doc://com.apple.documentation/documentation/Swift/AsyncSequence/unicodeScalars>, or <doc://com.apple.documentation/documentation/Swift/AsyncSequence/lines> to receive the content as asynchronous sequences of those types.

To wait until the session finishes transferring data and receive it in a single [`Data`](/documentation/Foundation/Data) instance, use [`data(from:delegate:)`](/documentation/Foundation/URLSession/data(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)