<!--
{
  "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/getAttachments(for:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKAttachmentStore(im)getAttachmentsForObject:completion:"
  },
  "title" : "getAttachments(for:completion:)"
}
-->

# getAttachments(for:completion:)

Returns all the attachments for the specified object.

```
func getAttachments(for object: HKObject, completion: @escaping @Sendable ([HKAttachment]?, (any Error)?) -> Void)
```

```
func attachments(for object: HKObject) async throws -> [HKAttachment]
```

## Parameters

`object`

An object from the HealthKit store.

`completion`

A completion handler that the system calls to return the attachment. This handler takes the following parameters:

- attachments: An array of attachments. 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 get all the attachments for the specified object.

```swift
let attachments: [HKAttachment]
do {
    attachments = try await attachmentStore.attachments(for: prescription)
} catch {
    // Handle the error here.
    fatalError("*** An error occurred while accessing the attachments for a prescription: \(error.localizedDescription) ***")
}

// Use the attachments 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)