---
title: HKAttachmentDataReader
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hkattachmentdatareader
---

# HKAttachmentDataReader

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

## Declaration

```swift
class HKAttachmentDataReader
```

## Overview

Overview To access the attachment’s data, get a data reader from the attachment store. 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. 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. // 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

- [data](healthkit/hkattachmentdatareader/data.md)
- [bytes](healthkit/hkattachmentdatareader/bytes.md)
- [progress](healthkit/hkattachmentdatareader/progress.md)

### Accessing the attachment object

- [attachment](healthkit/hkattachmentdatareader/attachment.md)

## See Also

### Attachments

- [HKAttachment](healthkit/hkattachment.md)
- [HKAttachmentStore](healthkit/hkattachmentstore.md)
