---
title: "addMetadata(_:completion:)"
framework: healthkit
role: symbol
role_heading: Instance Method
path: "healthkit/hkheartbeatseriesbuilder/addmetadata(_:completion:)"
---

# addMetadata(_:completion:)

Adds metadata to the sample.

## Declaration

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

```swift
func addMetadata(_ metadata: [String : Any]) async throws
```

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

## Discussion

Discussion The builder adds the metadata to the resulting series sample. It incorporates new data using addEntries(from:).

## See Also

### Adding Data

- [addHeartbeatWithTimeInterval(sinceSeriesStartDate:precededByGap:completion:)](healthkit/hkheartbeatseriesbuilder/addheartbeatwithtimeinterval(sinceseriesstartdate:precededbygap:completion:).md)
