<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKUnit/jouleUnit(with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKUnit(cm)jouleUnitWithMetricPrefix:"
  },
  "title" : "jouleUnit(with:)"
}
-->

# jouleUnit(with:)

Returns a HealthKit unit for measuring energy, using joule units with the provided prefix.

```
class func jouleUnit(with prefix: HKMetricPrefix) -> Self
```

## Parameters

`prefix`

A valid metric prefix value. For the complete list of prefix values, see [`HKMetricPrefix`](/documentation/HealthKit/HKMetricPrefix).

## Return Value

A HealthKit unit for measuring energy based on joules and the provided prefix.

## Discussion

This method is used to create prefixed versions of joules. HealthKit commonly uses kilojoules to measure food energy in many regions. Kilojoules can be created as shown below.

```swift
let kj = HKUnit.jouleUnitWithMetricPrefix(.Kilo)
```

---

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)