---
title: "insert(_:for:)"
framework: healthkit
role: symbol
role_heading: Instance Method
path: "healthkit/hkquantityseriessamplebuilder/insert(_:for:)"
---

# insert(_:for:)

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

## Declaration

```swift
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 doc://com.apple.healthkit/documentation/HealthKit/HKError/Code/errorInvalidArgument error if the date parameter is earlier than the series builder’s doc://com.apple.healthkit/documentation/HealthKit/HKQuantitySeriesSampleBuilder/startDate property.

## Discussion

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:)). note: You can insert quantities in any order. The builder sorts them by the date interval’s startDate property when you finish the series.

## See Also

### Adding Values

- [insert(_:at:)](healthkit/hkquantityseriessamplebuilder/insert(_:at:).md)
