A sample whose values are selected from a short list of possible values.
- iOS 8.0+
- Mac Catalyst 13.0+
- watchOS 2.0+
For example, you can use category samples to record sleep data using the
HKCategory 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.
HKCategory 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
HKCategory class should not be subclassed.
You may extend the
HKCategory class by adding metadata with custom keys as appropriate for your app. For more information, see