<!--
{
  "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/HKQuantitySeriesSampleBuilder/insert(_:for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKQuantitySeriesSampleBuilder(im)insertQuantity:dateInterval:error:"
  },
  "title" : "insert(_:for:)"
}
-->

# insert(_:for:)

Adds a new quantity to the series with the provided date interval.

```
func insert(_ quantity: HKQuantity, for dateInterval: DateInterval) throws
```

## Parameters

`quantity`

The quantity to insert.

`dateInterval`

The date interval associated with the quantity. If the interval’s <doc://com.apple.documentation/documentation/Foundation/DateInterval/start> parameter is the same as the start date for a previously provided quantity, this quantity replaces the previous one. This method fails with an [`HKError.Code.errorInvalidArgument`](/documentation/HealthKit/HKError/Code/errorInvalidArgument) error if the date parameter is earlier than the series builder’s [`startDate`](/documentation/HealthKit/HKQuantitySeriesSampleBuilder/startDate) property.

## Discussion

Use this method to add a quantity to the series. The quantity must have a unit that is compatible with the series builder’s quantity type (see [`is(compatibleWith:)`](/documentation/HealthKit/HKQuantityType/is(compatibleWith:))).

> Note:
> You can insert quantities in any order. The builder sorts them by the date interval’s <doc://com.apple.documentation/documentation/Foundation/NSDateInterval/startDate> property when you finish the series.

---

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)