---
title: "energyFormatterUnit(from:)"
framework: healthkit
role: symbol
role_heading: Type Method
path: "healthkit/hkunit/energyformatterunit(from:)"
---

# energyFormatterUnit(from:)

Converts a HealthKit unit object into a corresponding energy formatter enumeration value.

## Declaration

```swift
class func energyFormatterUnit(from unit: HKUnit) -> EnergyFormatter.Unit
```

## Parameters

- `unit`: A valid HealthKit unit object. If the unit is not an energy-type unit, this method throws an exception (doc://com.apple.documentation/documentation/Foundation/NSExceptionName/invalidArgumentException).

## Return Value

Return Value An energy formatter unit value. For a list of possible energy formatter unit values, see EnergyFormatter.Unit.

## See Also

### Working with formatter units

- [init(from:)](healthkit/hkunit/init(from:)-1j1pq.md)
- [lengthFormatterUnit(from:)](healthkit/hkunit/lengthformatterunit(from:).md)
- [init(from:)](healthkit/hkunit/init(from:)-55e1u.md)
- [massFormatterUnit(from:)](healthkit/hkunit/massformatterunit(from:).md)
- [init(from:)](healthkit/hkunit/init(from:)-7h2li.md)
