<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKAttachmentStore/getData(for:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKAttachmentStore(im)getDataForAttachment:completion:"
  },
  "title" : "getData(for:completion:)"
}
-->

# getData(for:completion:)

Returns an attachment’s data.

```
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:

- attachmentData: A <doc://com.apple.documentation/documentation/Foundation/Data> object that contains the attachment’s contents. If an error occurs, the system sets this parameter to `nil`.
- error: If an error occurred, this parameter contains information about the error. Otherwise, it’s `nil`.

## Discussion

Call this method to read the attachment’s contents directly from the attachment store.

```swift
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.
```

---

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)