<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKAttachmentStore"
  },
  "title" : "HKAttachmentStore"
}
-->

# HKAttachmentStore

The access point for attachments associated with samples in the HealthKit store.

```
class HKAttachmentStore
```

## Overview

Use an [`HKAttachmentStore`](/documentation/HealthKit/HKAttachmentStore) object to manage attachments for samples that your app has saved to the HealthKit store.

## Topics

### Creating an attachment store

[`init(healthStore: HKHealthStore)`](/documentation/HealthKit/HKAttachmentStore/init(healthStore:))

Creates an attachment store for the provided HealthKit store.

### Adding attachments

[`func addAttachment(to: HKObject, name: String, contentType: UTType, url: URL, metadata: [String : Any]) async throws -> HKAttachment`](/documentation/HealthKit/HKAttachmentStore/addAttachment(to:name:contentType:url:metadata:))

Asynchronously adds an attachment to the specified object.

[`func addAttachment(to: HKObject, name: String, contentType: UTType, url: URL, metadata: [String : Any], completion: (HKAttachment?, (any Error)?) -> Void)`](/documentation/HealthKit/HKAttachmentStore/addAttachment(to:name:contentType:url:metadata:completion:))

Adds an attachment to the specified object.

[`- (void) addAttachmentToObject:(HKObject *) object name:(NSString *) name contentType:(UTType *) contentType URL:(NSURL *) URL metadata:(NSDictionary<NSString *,id> *) metadata completion:(void (^)(HKAttachment *attachment, NSError *error)) completion;`](/documentation/HealthKit/HKAttachmentStore/addAttachmentToObject:name:contentType:URL:metadata:completion:)

Adds an attachment to the specified object.

### Accessing attachments

[`func getAttachments(for: HKObject, completion: ([HKAttachment]?, (any Error)?) -> Void)`](/documentation/HealthKit/HKAttachmentStore/getAttachments(for:completion:))

Returns all the attachments for the specified object.

[`func dataReader(for: HKAttachment) -> HKAttachmentDataReader`](/documentation/HealthKit/HKAttachmentStore/dataReader(for:))

Returns a data reader for the attachment.

[`func getData(for: HKAttachment, completion: (Data?, (any Error)?) -> Void) -> Progress`](/documentation/HealthKit/HKAttachmentStore/getData(for:completion:))

Returns an attachment’s data.

[`func streamData(for: HKAttachment, dataHandler: (Data?, (any Error)?, Bool) -> Void) -> Progress`](/documentation/HealthKit/HKAttachmentStore/streamData(for:dataHandler:))

Asynchronously returns the attachment’s data.

### Removing attachments

[`func removeAttachment(HKAttachment, from: HKObject, completion: (Bool, (any Error)?) -> Void)`](/documentation/HealthKit/HKAttachmentStore/removeAttachment(_:from:completion:))

Removes the specified attachment.

## Relationships

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Conforms To

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Equatable`](/documentation/Swift/Equatable)

---

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)