Instance Method

insert(_:for:)

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

Declaration

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 start parameter is the same as the start date for a previously provided quantity, this quantity replaces the previous one.

Fails with an HKError.Code.errorInvalidArgument error if the date parameter is earlier than the series builder’s 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:)).

See Also

Adding Values

func insert(HKQuantity, at: Date)

Adds a new quantity to the series at the provided date and time.