---
title: HKQuantitySample
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hkquantitysample
---

# HKQuantitySample

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

## Declaration

```swift
class HKQuantitySample
```

## Mentioned in

About the HealthKit framework Accessing condensed workout samples Saving data to HealthKit

## Overview

Overview 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 init(type:quantity:start:end:metadata:).

## Topics

### Creating Quantity Samples

- [init(type:quantity:start:end:)](healthkit/hkquantitysample/init(type:quantity:start:end:).md)
- [init(type:quantity:start:end:metadata:)](healthkit/hkquantitysample/init(type:quantity:start:end:metadata:).md)
- [init(type:quantity:start:end:device:metadata:)](healthkit/hkquantitysample/init(type:quantity:start:end:device:metadata:).md)

### Getting Property Data

- [quantity](healthkit/hkquantitysample/quantity.md)
- [count](healthkit/hkquantitysample/count.md)
- [quantityType](healthkit/hkquantitysample/quantitytype.md)

### Specifying Predicate Key Paths

- [HKPredicateKeyPathQuantity](healthkit/hkpredicatekeypathquantity.md)
- [HKPredicateKeyPathCount](healthkit/hkpredicatekeypathcount.md)

### Initializers

- [init(type:quantity:startDate:endDate:)](healthkit/hkquantitysample/init(type:quantity:startdate:enddate:).md)
- [init(type:quantity:startDate:endDate:device:metadata:)](healthkit/hkquantitysample/init(type:quantity:startdate:enddate:device:metadata:).md)
- [init(type:quantity:startDate:endDate:metadata:)](healthkit/hkquantitysample/init(type:quantity:startdate:enddate:metadata:).md)

## Relationships

### Inherits From

- [HKSample](healthkit/hksample.md)

### Inherited By

- [HKCumulativeQuantitySample](healthkit/hkcumulativequantitysample.md)
- [HKDiscreteQuantitySample](healthkit/hkdiscretequantitysample.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Basic samples

- [HKCumulativeQuantitySample](healthkit/hkcumulativequantitysample.md)
- [HKDiscreteQuantitySample](healthkit/hkdiscretequantitysample.md)
- [HKCategorySample](healthkit/hkcategorysample.md)
- [HKCorrelation](healthkit/hkcorrelation.md)
- [Units and quantities](healthkit/units-and-quantities.md)
- [Metadata Keys](healthkit/metadata-keys.md)
