<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKQuantity",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKQuantity"
  },
  "title" : "HKQuantity"
}
-->

# HKQuantity

An object that stores a value for a given unit.

```
class HKQuantity
```

## 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`](/documentation/HealthKit/HKQuantity) class. To help promote sharing data between apps, [`HKQuantity`](/documentation/HealthKit/HKQuantity) objects use only the units defined by the [`HKUnit`](/documentation/HealthKit/HKUnit) class.

## Topics

### Creating Quantities

[`+  quantityWithUnit:doubleValue:`](/documentation/HealthKit/HKQuantity/init(unit:doubleValue:))

Instantiates and returns a new quantity object.

### Working With Units

[`-  isCompatibleWithUnit:`](/documentation/HealthKit/HKQuantity/is(compatibleWith:))

Returns a boolean value indicating whether the quantity is compatible with the provided unit.

[`-  doubleValueForUnit:`](/documentation/HealthKit/HKQuantity/doubleValue(for:))

Returns the quantity’s value in the provided unit.

### Comparing Quantities

[`-  compare:`](/documentation/HealthKit/HKQuantity/compare(_:))

Compares two values after converting them to the same units.

## Relationships

### Conforms To

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`Equatable`](/documentation/Swift/Equatable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)