---
title: HKAttachment.AsyncBytes
framework: healthkit
role: symbol
role_heading: Structure
path: healthkit/hkattachment/asyncbytes
---

# HKAttachment.AsyncBytes

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

## Declaration

```swift
struct AsyncBytes
```

## Overview

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 using a for-await-in loop. // 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](swift/asyncsequence.md)

## See Also

### Accessing attachment data

- [name](healthkit/hkattachment/name.md)
- [identifier](healthkit/hkattachment/identifier.md)
- [contentType](healthkit/hkattachment/contenttype.md)
- [size](healthkit/hkattachment/size.md)
- [creationDate](healthkit/hkattachment/creationdate.md)
- [metadata](healthkit/hkattachment/metadata.md)
