<!--
{
  "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/URL/resourceBytes",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation3URLV13resourceBytesAC05AsyncD0Vvp"
  },
  "title" : "resourceBytes"
}
-->

# resourceBytes

The URL’s resource data, as an asynchronous sequence of bytes.

```
var resourceBytes: URL.AsyncBytes { get }
```

## Discussion

Use this property with Swift’s `for`-`await`-`in` syntax, to read the contents of a URL byte-by-byte, like this:

```swift
guard let url = URL(string: "https://www.example.com") else {
    return
}
do {
    // Read each byte of the data as it becomes available.
    for try await byte in url.resourceBytes
    {
        // Do something with byte.
    }
} catch {
    print ("Error: \(error)")
}
```

To wait for the entire resource to load, use the [`URLSession`](/documentation/Foundation/URLSession) method [`data(from:delegate:)`](/documentation/Foundation/URLSession/data(from:delegate:)) with the `await` keyword. [`URLSession`](/documentation/Foundation/URLSession) also offers methods to upload data to a URL endpoint and download a URL’s contents to a file.

---

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)