---
title: "streamData(for:dataHandler:)"
framework: healthkit
role: symbol
role_heading: Instance Method
path: "healthkit/hkattachmentstore/streamdata(for:datahandler:)"
---

# streamData(for:dataHandler:)

Asynchronously returns the attachment’s data.

## Declaration

```swift
func streamData(for attachment: HKAttachment, dataHandler: @escaping (Data?, (any Error)?, Bool) -> Void) -> Progress
```

## Parameters

- `attachment`: An attachment associated with an object in the HealthKit store.
- `dataHandler`: A closure that the system calls repeatedly to return the attachment’s contents. This closure takes the following parameters:

## Discussion

Discussion Call this method to incrementally read the attachment’s contents directly from the attachment store. var data = Data() attachmentStore.streamData(for: myAttachment) { dataChunk, error, done in          if let error {         // Handle the error here.         fatalError("*** An error occurred while streaming the attachment's data. \(error.localizedDescription) ***")     }          guard let dataChunk else { return }          data.append(dataChunk)          if done {         // Use the attachment's data here.         print(data)     } }

## See Also

### Accessing attachments

- [getAttachments(for:completion:)](healthkit/hkattachmentstore/getattachments(for:completion:).md)
- [dataReader(for:)](healthkit/hkattachmentstore/datareader(for:).md)
- [getData(for:completion:)](healthkit/hkattachmentstore/getdata(for:completion:).md)
