Class

HKCategorySample

The HKCategorySample class is a concrete subclass of the HKSample class. This class describes samples whose values are selected from an enumeration of values.

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.

Category samples are immutable: The sample’s properties are set when the object is first created, and they cannot change.

Subclassing Notes

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 init(type:value:start:end:metadata:).

Topics

Creating Category Samples

init(type: HKCategoryType, value: Int, start: Date, end: Date)

Creates a newly instantiated category sample.

init(type: HKCategoryType, value: Int, start: Date, end: Date, metadata: [String : Any]?)

Creates a newly instantiated category sample with the provided metadata.

init(type: HKCategoryType, value: Int, start: Date, end: Date, device: HKDevice?, metadata: [String : Any]?)

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

Getting Property Data

var categoryType: HKCategoryType

The category type for this sample.

var value: Int

The category value for this sample.

Constants

Predicate key path

A constant that can be used to create predicate format strings.

Relationships

Inherits From

Conforms To