HKCategoryValueSleepAnalysis
Categories that represent the result of a sleep analysis.
Declaration
enum HKCategoryValueSleepAnalysisMentioned in
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.
[Image]
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.
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
Values for Tracking Sleep States
HKCategoryValueSleepAnalysis.awakeHKCategoryValueSleepAnalysis.asleepCoreHKCategoryValueSleepAnalysis.asleepDeepHKCategoryValueSleepAnalysis.asleepREMHKCategoryValueSleepAnalysis.asleepUnspecified
Deprecated values
Initializers
Type Properties
See Also
Assigning Values
HKCategoryValueHKCategoryValueCervicalMucusQualityHKCategoryValueMenstrualFlowHKCategoryValueOvulationTestResultHKCategoryValueContraceptiveHKCategoryValueAppetiteChangesHKCategoryValuePresenceHKCategoryValueSeverityHKCategoryValueEnvironmentalAudioExposureEventHKCategoryValueHeadphoneAudioExposureEventHKCategoryValueLowCardioFitnessEventHKAppleWalkingSteadinessClassificationHKCategoryValueAppleWalkingSteadinessEventHKCategoryValuePregnancyTestResultHKCategoryValueProgesteroneTestResult