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

# addMetadata(_:completion:)

Adds metadata to the sample.

```
func addMetadata(_ metadata: [String : Any], completion: @escaping @Sendable (Bool, (any Error)?) -> Void)
```

## Parameters

`metadata`

The metadata dictionary contains extra information describing all the samples created by the builder. The dictionary’s keys are all strings. The values may be strings, numbers, or date objects. For a complete list of predefined metadata keys, see <doc://com.apple.healthkit/documentation/HealthKit/metadata-keys>.

    Using predefined keys helps facilitate sharing data between apps; however, you are also encouraged to create your own, custom keys as needed to extend the samples’ capabilities.

`completion`

The completion handler called by the builder after it attempts to add the metadata to the series. The completion handler takes the following parameters:

- `success`: A Boolean value that indicates whether the builder successfully added the heartbeat.
- `error`: If the `success` parameter is <doc://com.apple.documentation/documentation/Foundation/NSExpression/false>, this contains an object that describes the error; otherwise, `nil`.

## Discussion

The builder adds the metadata to the resulting series sample. It incorporates new data using <doc://com.apple.documentation/documentation/Foundation/NSMutableDictionary/addEntries(from:)>.

---

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)