---
title: "finishSeries(metadata:completion:)"
framework: healthkit
role: symbol
role_heading: Instance Method
path: "healthkit/hkquantityseriessamplebuilder/finishseries(metadata:completion:)"
---

# finishSeries(metadata:completion:)

Finalizes the series and returns the resulting quantity samples.

## Declaration

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

```swift
func finishSeries(metadata: [String : Any]?) async throws -> [HKQuantitySample]
```

## 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`: A completion handler, called by the builder after it creates the samples. The handler takes the following parameters:

## Discussion

Discussion Call finishSeries(metadata:completion:) after inserting all the quantities for the series. The series builder creates one or more samples to represent the series, saves the samples to the HealthKit store, and passes them to the completion handler. note: The series builder typically creates a single sample that contains all the inserted quantities; however, it may split the quantities up into multiple sample objects. Calling this method before inserting any samples results in an error. Also, calling this method invalidates the series builder; you cannot call any other series builder methods after calling this method. This method calls finishSeries(metadata:endDate:completion:), passing nil as the endDate parameter.

## See Also

### Ending the Collection

- [discard()](healthkit/hkquantityseriessamplebuilder/discard().md)
- [finishSeries(metadata:endDate:completion:)](healthkit/hkquantityseriessamplebuilder/finishseries(metadata:enddate:completion:).md)
