---
title: "getData(for:completion:)"
framework: healthkit
role: symbol
role_heading: Instance Method
path: "healthkit/hkattachmentstore/getdata(for:completion:)"
---

# getData(for:completion:)

Returns an attachment’s data.

## Declaration

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

## Parameters

- `attachment`: An attachment associated with an object in the HealthKit store.
- `completion`: A completion handler that the system calls to return the data. This handler takes the following parameters:

## Discussion

Discussion Call this method to read the attachment’s contents directly from the attachment store. let progress = attachmentStore.getData(for: myAttachment) { data, error in     if let error {         // Handle the error here.         fatalError("*** An error occurred while accessing the attachment's data. \(error.localizedDescription) ***")     }          // Use the data here. }

// Monitor the progress here.

## See Also

### Accessing attachments

- [getAttachments(for:completion:)](healthkit/hkattachmentstore/getattachments(for:completion:).md)
- [dataReader(for:)](healthkit/hkattachmentstore/datareader(for:).md)
- [streamData(for:dataHandler:)](healthkit/hkattachmentstore/streamdata(for:datahandler:).md)
