---
title: HKCategoryValueSleepAnalysis
framework: healthkit
role: symbol
role_heading: Enumeration
path: healthkit/hkcategoryvaluesleepanalysis
---

# HKCategoryValueSleepAnalysis

Categories that represent the result of a sleep analysis.

## Declaration

```swift
enum HKCategoryValueSleepAnalysis
```

## Mentioned in

Saving data to HealthKit

## Overview

Overview These values provide the set of valid categories for sleep tracking in HealthKit. To record a sleep sample, create an HKCategorySample using a sleepAnalysis identifier and a HKCategoryValueSleepAnalysis value. let sleepSampleType = HKCategoryType(.sleepAnalysis) let sleepCategory = HKCategoryValueSleepAnalysis.asleepDeep.rawValue let deepSleepSample  = HKCategorySample(type: sleepSampleType,                                         value:sleepCategory,                                         start: startDate,                                         end: endDate) Each sleep analysis sample can have only one value. To track both the amount of time a person spends in bed and the quality and quantity of their sleep, use samples with overlapping times.

One set of samples tracks the amount of time the user spent in bed. Then, you can partition the in-bed time into a more-detailed set of samples. These detailed samples show when the user was awake, in core sleep, in deep sleep, or in rapid eye movement (REM) sleep. The detailed samples overlap the in-bed sample, but they don’t overlap each other. note: Samples recorded by Apple Watch only include awake samples that occur between two sleep samples. When reading sleep samples from HealthKit, there might not be any detailed samples that correspond to the beginning or ending of an in-bed sample. By comparing the start and end times of these samples, apps can calculate secondary statistics. For example: the amount of time it took for the user to fall asleep, the percentage of sleep time spent in deep sleep, the number of times the user woke while in bed, and the total amount of time spent both in bed and asleep.

## Topics

### Values for Tracking Time In-Bed

- [HKCategoryValueSleepAnalysis.inBed](healthkit/hkcategoryvaluesleepanalysis/inbed.md)

### Values for Tracking Sleep States

- [HKCategoryValueSleepAnalysis.awake](healthkit/hkcategoryvaluesleepanalysis/awake.md)
- [HKCategoryValueSleepAnalysis.asleepCore](healthkit/hkcategoryvaluesleepanalysis/asleepcore.md)
- [HKCategoryValueSleepAnalysis.asleepDeep](healthkit/hkcategoryvaluesleepanalysis/asleepdeep.md)
- [HKCategoryValueSleepAnalysis.asleepREM](healthkit/hkcategoryvaluesleepanalysis/asleeprem.md)
- [HKCategoryValueSleepAnalysis.asleepUnspecified](healthkit/hkcategoryvaluesleepanalysis/asleepunspecified.md)

### Deprecated values

- [asleep](healthkit/hkcategoryvaluesleepanalysis/asleep.md)

### Initializers

- [init(rawValue:)](healthkit/hkcategoryvaluesleepanalysis/init(rawvalue:).md)

### Type Properties

- [allAsleepValues](healthkit/hkcategoryvaluesleepanalysis/allasleepvalues.md)

## Relationships

### Conforms To

- [BitwiseCopyable](swift/bitwisecopyable.md)
- [Copyable](swift/copyable.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [HKCategoryValuePredicateProviding](healthkit/hkcategoryvaluepredicateproviding.md)
- [Hashable](swift/hashable.md)
- [RawRepresentable](swift/rawrepresentable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Assigning Values

- [HKCategoryValue](healthkit/hkcategoryvalue.md)
- [HKCategoryValueCervicalMucusQuality](healthkit/hkcategoryvaluecervicalmucusquality.md)
- [HKCategoryValueMenstrualFlow](healthkit/hkcategoryvaluemenstrualflow.md)
- [HKCategoryValueOvulationTestResult](healthkit/hkcategoryvalueovulationtestresult.md)
- [HKCategoryValueContraceptive](healthkit/hkcategoryvaluecontraceptive.md)
- [HKCategoryValueAppetiteChanges](healthkit/hkcategoryvalueappetitechanges.md)
- [HKCategoryValuePresence](healthkit/hkcategoryvaluepresence.md)
- [HKCategoryValueSeverity](healthkit/hkcategoryvalueseverity.md)
- [HKCategoryValueEnvironmentalAudioExposureEvent](healthkit/hkcategoryvalueenvironmentalaudioexposureevent.md)
- [HKCategoryValueHeadphoneAudioExposureEvent](healthkit/hkcategoryvalueheadphoneaudioexposureevent.md)
- [HKCategoryValueLowCardioFitnessEvent](healthkit/hkcategoryvaluelowcardiofitnessevent.md)
- [HKAppleWalkingSteadinessClassification](healthkit/hkapplewalkingsteadinessclassification.md)
- [HKCategoryValueAppleWalkingSteadinessEvent](healthkit/hkcategoryvalueapplewalkingsteadinessevent.md)
- [HKCategoryValuePregnancyTestResult](healthkit/hkcategoryvaluepregnancytestresult.md)
- [HKCategoryValueProgesteroneTestResult](healthkit/hkcategoryvalueprogesteronetestresult.md)
