---
title: HKQuantity
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hkquantity
---

# HKQuantity

An object that stores a value for a given unit.

## Declaration

```swift
class HKQuantity
```

## Mentioned in

Defining and converting units and quantities Saving data to HealthKit

## Overview

Overview HealthKit uses quantity objects to store numerical data. When you create a quantity, you provide both the quantity’s value and unit. Quantities are immutable objects: Their values are set when the object is first created and cannot change. Converting Units You can request the value from a quantity object in any compatible units. For example,  if you create a length quantity in feet, you can then request the length in meters. The quantity object automatically converts its value to the requested units. Using Quantities As with many HealthKit classes, don’t subclass the HKQuantity class. To help promote sharing data between apps, HKQuantity objects use only the units defined by the HKUnit class.

## Topics

### Creating Quantities

- [init(unit:doubleValue:)](healthkit/hkquantity/init(unit:doublevalue:).md)

### Working With Units

- [is(compatibleWith:)](healthkit/hkquantity/is(compatiblewith:).md)
- [doubleValue(for:)](healthkit/hkquantity/doublevalue(for:).md)

### Comparing Quantities

- [compare(_:)](healthkit/hkquantity/compare(_:).md)

### Initializers

- [init(coder:)](healthkit/hkquantity/init(coder:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.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)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Units and quantities

- [Defining and converting units and quantities](healthkit/defining-and-converting-units-and-quantities.md)
- [HKUnit](healthkit/hkunit.md)
- [HKMetricPrefix](healthkit/hkmetricprefix.md)
