Samples
Create and save health and fitness samples.
Overview
The HealthKit store saves most health and fitness data using HKSample subclasses. All sample subclasses record information at a specified time. If the sample’s startDate and endDate properties are the same, the sample represents a point in time. If the endDate is after the startDate, the sample represents a time interval.
HealthKit uses different HKSample subclasses to store different types of data:
HKQuantitySample objects store quantities—a numerical value and units. Most HealthKit data types use quantity samples. For example, height, heart rate, and dietary energy consumed all use quantity samples.
HKCategorySample objects store a single option selected from a short list. For example, category samples record sleep data (the user can be in bed, asleep, or awake).
HKCorrelation samples combine two or more samples into a single value. For example, correlation samples represent food intake and blood pressure samples. A food sample contains any number of nutrition samples, while a blood pressure sample contains both a systolic and a diastolic sample.
HealthKit represents specialized data types with sample subclasses such as HKCDADocumentSample, HKWorkoutRoute, and HKWorkout.
Topics
Essentials
Basic samples
HKCumulativeQuantitySampleHKDiscreteQuantitySampleHKQuantitySampleHKCategorySampleHKCorrelationUnits and quantitiesMetadata Keys
Series data
Electrocardiograms
Audiograms
Medical records
Accessing Health RecordsAccessing Sample Data in the SimulatorAccessing a User’s Clinical RecordsAccessing Data from a SMART Health CardHKClinicalRecordHKFHIRResourceHKVerifiableClinicalRecordHKVerifiableClinicalRecordSubjectHKCDADocumentSampleHKDocumentSampleCDAHKDocumentType
Vision prescriptions
HKVisionPrescriptionHKGlassesPrescriptionHKContactsPrescriptionHKGlassesLensSpecificationHKContactsLensSpecificationHKLensSpecificationHKVisionPrismHKPrescriptionType