<!--
{
  "availability" : [
    "iOS: 12.0.0 -",
    "iPadOS: 12.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 5.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKQuantitySeriesSampleBuilder/finishSeries(metadata:endDate:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKQuantitySeriesSampleBuilder(im)finishSeriesWithMetadata:endDate:completion:"
  },
  "title" : "finishSeries(metadata:endDate:completion:)"
}
-->

# finishSeries(metadata:endDate:completion:)

Finalizes the series with the provided end date, and returns the resulting quantity samples.

```
func finishSeries(metadata: [String : Any]?, endDate: Date?, completion: @escaping @Sendable ([HKQuantitySample]?, (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.

`endDate`

The date when the sample ends. If `nil`, the builder uses the latest end date from the contained quantities.

    The sample builder returns an [`HKError.Code.errorInvalidArgument`](/documentation/HealthKit/HKError/Code/errorInvalidArgument)     error if the     `endDate`     is earlier than the builder’s [`startDate`](/documentation/HealthKit/HKQuantitySeriesSampleBuilder/startDate)     parameter, or is earlier than the end date of any of the quantities inserted into the builder.

`completion`

A completion handler, called by the builder after it creates the samples.

    The handler takes the following parameters:

- **samples**: The samples returned by the builder, or `nil` if an error occurs.
- **error**: If an error occurs, this contains an object that describes the error. Otherwise, it is `nil`.

## Discussion

Call [`finishSeries(metadata:endDate:completion:)`](/documentation/HealthKit/HKQuantitySeriesSampleBuilder/finishSeries(metadata:endDate:completion:)) after inserting all the quantities for the series. The series builder then creates one or more samples to represent the series, saves the samples to the HealthKit store, and then 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.

---

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)