A sample that represents a quantity, including the value and the units.


@interface HKQuantitySample : HKSample


A quantity sample contains one or more HKQuantity objects. Each quantity represents a single piece of data with a single numeric value and the value’s associated units. For example, you can use quantity samples to record the user’s height, the user’s current heart rate, or the number of calories in a hamburger. HealthKit provides a wide range of quantity types, letting you track many different health and fitness features.

The HKQuantitySample class is a subclass of the HKSample class. Quantity samples are immutable; you set the sample’s properties when you create it, and they cannot change.

In iOS 13 and later and watchOS 6 and later, HKQuantitySample is an abstract superclass for the HKCumulativeQuantitySample and HKDiscreteQuantitySample concrete subclasses. The system automatically selects the correct subclass based on the HKQuantityType object used to create the sample.

Extend Quantity Samples

Like many HealthKit classes, you should not subclass the HKQuantitySample class. You may extend this class by adding metadata with custom keys to save related data used by your app.

For more information, see quantitySampleWithType:quantity:startDate:endDate:metadata:.


Creating Quantity Samples

+ quantitySampleWithType:quantity:startDate:endDate:

Returns a sample containing a numeric measurement.

+ quantitySampleWithType:quantity:startDate:endDate:metadata:

Returns a sample containing a numeric measurement with the provided metadata.

+ quantitySampleWithType:quantity:startDate:endDate:device:metadata:

Returns a sample containing a numeric measurement with the provided device and metadata.

Getting Property Data


The quantity for this sample.


The number of quantities contained in this sample.


The quantity type for this sample.

Specifying Predicate Key Paths


The key path for accessing the sample’s quantity.


A key path for the sample’s count.


Inherits From

See Also

Abstract Superclasses


A HealthKit sample represents a piece of data associated with a start and end time.


A piece of data that can be stored inside the HealthKit store.