<!--
{
  "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/HKAttachmentDataReader",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "s:9HealthKit22HKAttachmentDataReaderC"
  },
  "title" : "HKAttachmentDataReader"
}
-->

# HKAttachmentDataReader

A reader that provides access to an attachment’s data.

```
class HKAttachmentDataReader
```

## Overview

To access the attachment’s data, get a data reader from the attachment store.

```swift
let attachmentStore = HKAttachmentStore(healthStore: store)

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

You can then asynchronously access the whole data object.

```swift
let data: Data
do {
    data = try await dataReader.data
} catch {
    // Handle the error here.
    fatalError("*** An error occurred while accessing the attachment's data. \(error.localizedDescription) ***")
}
```

Alternatively, you can access the file’s contents as an asynchronous sequence of bytes.

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

## Topics

### Reading attachment data

[`var data: Data`](/documentation/HealthKit/HKAttachmentDataReader/data)

The abstract’s data.

[`var bytes: HKAttachment.AsyncBytes`](/documentation/HealthKit/HKAttachmentDataReader/bytes)

An asynchronous sequence that provides the attachment’s data.

[`var progress: Progress`](/documentation/HealthKit/HKAttachmentDataReader/progress)

An object you can use to track the progress while reading an attachment’s data.

### Accessing the attachment object

[`var attachment: HKAttachment`](/documentation/HealthKit/HKAttachmentDataReader/attachment)

An attachment object that represents the file from which the reader is reading.



---

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)