<!--
{
  "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/HKCategoryValueSleepAnalysis",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:@E@HKCategoryValueSleepAnalysis"
  },
  "title" : "HKCategoryValueSleepAnalysis"
}
-->

# HKCategoryValueSleepAnalysis

Categories that represent the result of a sleep analysis.

```
enum HKCategoryValueSleepAnalysis
```

## Overview

These values provide the set of valid categories for sleep tracking in HealthKit. To record a sleep sample, create an [`HKCategorySample`](/documentation/HealthKit/HKCategorySample) using a [`sleepAnalysis`](/documentation/HealthKit/HKCategoryTypeIdentifier/sleepAnalysis) identifier and a [`HKCategoryValueSleepAnalysis`](/documentation/HealthKit/HKCategoryValueSleepAnalysis) value.

```swift
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.

![An illustration showing the in-bed sample and the overlapping awake, REM, core and deep sleep samples.](images/com.apple.healthkit/media-4110084@2x.png)

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

[`HKCategoryValueSleepAnalysisInBed`](/documentation/HealthKit/HKCategoryValueSleepAnalysis/inBed)

The user is in bed.

### Values for Tracking Sleep States

[`HKCategoryValueSleepAnalysisAwake`](/documentation/HealthKit/HKCategoryValueSleepAnalysis/awake)

The user is awake.

[`HKCategoryValueSleepAnalysisAsleepCore`](/documentation/HealthKit/HKCategoryValueSleepAnalysis/asleepCore)

The user is in light or intermediate sleep.

[`HKCategoryValueSleepAnalysisAsleepDeep`](/documentation/HealthKit/HKCategoryValueSleepAnalysis/asleepDeep)

The user is in deep sleep.

[`HKCategoryValueSleepAnalysisAsleepREM`](/documentation/HealthKit/HKCategoryValueSleepAnalysis/asleepREM)

The user is in REM sleep.

[`HKCategoryValueSleepAnalysisAsleepUnspecified`](/documentation/HealthKit/HKCategoryValueSleepAnalysis/asleepUnspecified)

The user is asleep, but the specific stage isn’t known.

### Deprecated values

[`HKCategoryValueSleepAnalysisAsleep`](/documentation/HealthKit/HKCategoryValueSleepAnalysis/asleep)

The user is sleeping.

## Relationships

### Conforms To

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

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

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

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

[`HKCategoryValuePredicateProviding`](/documentation/HealthKit/HKCategoryValuePredicateProviding)

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

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

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

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

---

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)