Class

HKCategorySample

A sample whose values are selected from a short list of possible values.

Declaration

@interface HKCategorySample : HKSample

Overview

For example, you can use category samples to record sleep data using the HKCategoryValueSleepAnalysis enumeration. Individual samples represent time periods when the user is in bed or asleep. Samples with different values may have overlapping time intervals. For example, when the user is both in bed and asleep, you would create an in-bed sample and an asleep sample with overlapping times.

The HKCategorySample class is a concrete subclass of the HKSample class. Category samples are immutable: The sample’s properties are set when the object is first created, and they cannot change.

Using Category Samples

Like many HealthKit classes, the HKCategorySample class should not be subclassed.

You may extend the HKCategorySample class by adding metadata with custom keys as appropriate for your app. For more information, see categorySampleWithType:value:startDate:endDate:metadata:.

Topics

Creating Category Samples

+ categorySampleWithType:value:startDate:endDate:

Creates a newly instantiated category sample.

+ categorySampleWithType:value:startDate:endDate:metadata:

Creates a newly instantiated category sample with the provided metadata.

+ categorySampleWithType:value:startDate:endDate:device:metadata:

Creates a newly instantiated category sample including the provided device and metadata.

Getting Property Data

categoryType

The category type for this sample.

value

The category value for this sample.

Valid Values

HKCategoryValue

Miscellaneous category values.

HKCategoryValueCervicalMucusQuality

Categories used to represent the user’s cervical mucus quality.

HKCategoryValueMenstrualFlow

Categories indicating the amount of menstrual flow for a given sample.

HKCategoryValueOvulationTestResult

Categories used to represent the result of an ovulation home test.

HKCategoryValueSleepAnalysis

Categories used when analyzing sleep samples.

HKCategoryValueAudioExposureEvent

Categories indicating audio exposure events.

Predicate Key Paths

HKPredicateKeyPathCategoryValue

The key path for the category sample’s value.

Relationships

Inherits From

See Also

First Steps

Saving Data to HealthKit

Create and share HealthKit samples.

HKCumulativeQuantitySample

A sample that represents a cumulative quantity.

HKDiscreteQuantitySample

A sample that represents a discrete quantity.

HKQuantitySample

A sample that represents a quantity, including the value and the units.

HKCorrelation

A sample that groups multiple related samples into a single entry.

Units and Quantities

Objects used to specify a quantity for a given unit (for example, 175 lbs), and to convert between units (79.4 kg).

Metadata Keys

Constants used to add metadata to objects stored in HealthKit.