Class

HKQuantitySample

The HKQuantitySample class is a concrete subclass of the HKSample class. Each quantity sample instance represent a piece of data with a single numeric value. For example, you can use a quantity sample to record the user’s height, the user’s current heart rate, or the number of calories in a hamburger. HealthKit provides a wide range of quantity types, letting you track a number of different health and fitness features.

Overview

Quantity samples are immutable: You set the sample’s properties when you create it, and they cannot change.

Subclassing Notes

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

You may extend the HKQuantitySample class by adding metadata with custom keys as appropriate for your app. For more information, see init(type:quantity:start:end:metadata:).

Topics

Creating Quantity Samples

init(type: HKQuantityType, quantity: HKQuantity, start: Date, end: Date)

Returns a sample containing a numeric measurement.

init(type: HKQuantityType, quantity: HKQuantity, start: Date, end: Date, metadata: [String : Any]?)

Returns a sample containing a numeric measurement with the provided metadata.

init(type: HKQuantityType, quantity: HKQuantity, start: Date, end: Date, device: HKDevice?, metadata: [String : Any]?)

Returns a sample containing a numeric measurement with the provided device and metadata.

Getting Property Data

var quantity: HKQuantity

The quantity for this sample.

var quantityType: HKQuantityType

The quantity type for this sample.

Constants

Quantity Predicate Keys

Constants that can be used to create predicate format strings.

Relationships

Inherits From

Conforms To