<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKAttachment/AsyncBytes",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "s:So12HKAttachmentC9HealthKitE10AsyncBytesV"
  },
  "title" : "HKAttachment.AsyncBytes"
}
-->

# HKAttachment.AsyncBytes

An asynchronous sequence that returns the attached file as a series of bytes.

```
struct AsyncBytes
```

## Overview

To access the attachment file as an asynchronous sequence of bytes, get a data reader from the attachment store, and then access its [`bytes`](/documentation/HealthKit/HKAttachmentDataReader/bytes) using a `for-await-in` loop.

```swift
// Get a data reader for the attachment.
let dataReader = attachmentStore.dataReader(for: myAttachment)

// Asynchronously access the attachment's bytes.
var data = Data()
do {
    for try await byte in dataReader.bytes {
        data.append(byte)
    }
} catch {
    // Handle the error here.
    fatalError("*** An error occurred while reading the attachment's data: \(error.localizedDescription) ***")
}

// Use the data here.
```

## Relationships

### Conforms To

[`AsyncSequence`](/documentation/Swift/AsyncSequence)

---

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)