Instance Method


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


- (void)finishSeriesWithMetadata:(NSDictionary<NSString *,id> *)metadata endDate:(NSDate *)endDate completion:(void (^)(NSArray<__kindof HKQuantitySample *> *samples, NSError *error))completion;



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 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..


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

The sample builder returns an HKErrorInvalidArgument error if the endDate is earlier than the builder’s startDate parameter, or is earlier than the end date of any of the quantities inserted into the builder.


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

The handler takes the following parameters:


The samples returned by the builder, or nil if an error occurs.


If an error occurs, this contains an object that describes the error. Otherwise, it is nil.


Call finishSeriesWithMetadata: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.

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.

See Also

Ending the Collection

- discard

Discards all previously collected data and invalidates the builder.

- finishSeriesWithMetadata:completion:

Finalizes the series and returns the resulting quantity samples.