---
title: HKCategorySample
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hkcategorysample
---

# HKCategorySample

A sample with values from a short list of possible values.

## Declaration

```swift
class HKCategorySample
```

## Mentioned in

About the HealthKit framework Recording and querying menopausal state Saving data to HealthKit

## Overview

Overview You can use category samples to record data associated with a HKCategoryType. The value for the sample must come from the appropriate category value enumeration. Each category type uses its own enumeration. Individual samples represent a value and time period. Samples with different values may have overlapping time intervals. The HKCategorySample class is a concrete subclass of the HKSample class. Category samples are immutable: You set the sample’s properties when you create it, and they can’t change. Extend Category Samples Like many HealthKit classes, don’t subclass the HKCategorySample class. You may extend the HKCategorySample class by adding metadata with custom keys as appropriate for your app. For more information, see init(type:value:start:end:metadata:).

## Topics

### Creating Category Samples

- [init(type:value:start:end:)](healthkit/hkcategorysample/init(type:value:start:end:).md)
- [init(type:value:start:end:metadata:)](healthkit/hkcategorysample/init(type:value:start:end:metadata:).md)
- [init(type:value:start:end:device:metadata:)](healthkit/hkcategorysample/init(type:value:start:end:device:metadata:).md)

### Getting Property Data

- [categoryType](healthkit/hkcategorysample/categorytype.md)
- [value](healthkit/hkcategorysample/value.md)

### Assigning Values

- [HKCategoryValue](healthkit/hkcategoryvalue.md)
- [HKCategoryValueCervicalMucusQuality](healthkit/hkcategoryvaluecervicalmucusquality.md)
- [HKCategoryValueMenstrualFlow](healthkit/hkcategoryvaluemenstrualflow.md)
- [HKCategoryValueOvulationTestResult](healthkit/hkcategoryvalueovulationtestresult.md)
- [HKCategoryValueContraceptive](healthkit/hkcategoryvaluecontraceptive.md)
- [HKCategoryValueSleepAnalysis](healthkit/hkcategoryvaluesleepanalysis.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)
- [HKCategoryValueAudioExposureEvent](healthkit/hkcategoryvalueaudioexposureevent.md)

### Specifying Predicate Key Paths

- [HKPredicateKeyPathCategoryValue](healthkit/hkpredicatekeypathcategoryvalue.md)

### Initializers

- [init(type:value:startDate:endDate:)](healthkit/hkcategorysample/init(type:value:startdate:enddate:).md)
- [init(type:value:startDate:endDate:device:metadata:)](healthkit/hkcategorysample/init(type:value:startdate:enddate:device:metadata:).md)
- [init(type:value:startDate:endDate:metadata:)](healthkit/hkcategorysample/init(type:value:startdate:enddate:metadata:).md)

## Relationships

### Inherits From

- [HKSample](healthkit/hksample.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Basic samples

- [HKCumulativeQuantitySample](healthkit/hkcumulativequantitysample.md)
- [HKDiscreteQuantitySample](healthkit/hkdiscretequantitysample.md)
- [HKQuantitySample](healthkit/hkquantitysample.md)
- [HKCorrelation](healthkit/hkcorrelation.md)
- [Units and quantities](healthkit/units-and-quantities.md)
- [Metadata Keys](healthkit/metadata-keys.md)
