Specify the kind of data used in HealthKit.
Framework
- Health
Kit
Overview
HealthKit uses HKObject
subclasses to identify the different types of data stored in HealthKit:
HKCharacteristic
represents data that does not typically change over time (for example, blood type).Type HKQuantity
represents samples that contain a numeric value (for example calories consumed).Type HKCategory
represents samples that contain an option from a short list of possible values (for example sleep analysis).Type HKCorrelation
represents complex samples that contain a number of quantity or category samples (for example, a food sample that includes a number of nutrition samples).Type HKWorkout
represents a workout and its associated data (for more information, see Workouts).Type Other object types (for example,
HKActivity
,Summary Type HKDocument
, andType HKSeries
) represent other, specialized data types.Type
To create a type object, call the appropriate HKObject
class method, and pass in the desired type identifier.
let bloodType = HKObjectType.characteristicType(forIdentifier: .bloodType)
let caloriesConsumed = HKObjectType.quantityType(forIdentifier: .dietaryEnergyConsumed)
let sleepAnalysis = HKObjectType.categoryType(forIdentifier: .sleepAnalysis)
You can use the resulting object types to request permission to access the data, to save new data to the HealthKit store, or to read data from the HealthKit store.