HKQuery
An abstract class for all the query classes in HealthKit.
Declaration
class HKQueryMentioned in
Overview
The HKQuery class is the basis for all the query objects that retrieve data from the HealthKit store. The HKQuery class is an abstract class. You should never instantiate it directly. Instead, you always work with one of its concrete subclasses.
Filter queries using predicates
All the concrete HKQuery subclasses take a predicate. You can use this predicate to filter the samples returned by the query. When HealthKit runs a query, it converts the predicate to SQL and executes the SQL on the underlying store. This has two important side effects.
Predicates improve the performance of your query, both in terms of speed and memory usage. Because the store executes the predicate, it restricts the number of HealthKit objects that it instantiates and returns.
Since the store executes these predicates, it limits the type of predicates that you can use. Specifically, HealthKit provides several predicate key paths (for example, HKPredicateKeyPathUUID and HKPredicateKeyPathMetadata). You can create predicates using only these key paths.
Topics
Accessing properties
Creating object predicates
predicateForObject(with:)predicateForObjects(with:)predicateForObjects(from:)predicateForObjects(from:)predicateForObjects(from:)predicateForObjects(withDeviceProperty:allowedValues:)predicateForObjects(from:)predicateForObjects(withMetadataKey:)predicateForObjects(withMetadataKey:allowedValues:)predicateForObjects(withMetadataKey:operatorType:value:)predicateForObjectsWithNoCorrelation()
Creating sample predicates
Creating quantity sample predicates
Creating category sample predicates
Creating clinical record predicates
predicateForClinicalRecords(from:fhirResourceType:identifier:)predicateForClinicalRecords(withFHIRResourceType:)predicateForVerifiableClinicalRecords(withRelevantDateWithin:)
Creating workout predicates
predicateForObjects(from:)predicateForWorkouts(with:)predicateForWorkouts(activityPredicate:)predicateForWorkouts(with:duration:)predicateForWorkouts(operatorType:quantityType:averageQuantity:)predicateForWorkouts(operatorType:quantityType:maximumQuantity:)predicateForWorkouts(operatorType:quantityType:minimumQuantity:)predicateForWorkouts(operatorType:quantityType:sumQuantity:)predicateForWorkouts(with:totalDistance:)predicateForWorkouts(with:totalEnergyBurned:)predicateForWorkouts(with:totalFlightsClimbed:)predicateForWorkouts(with:totalSwimmingStrokeCount:)
Creating workout activity predicates
predicateForWorkoutActivities(workoutActivityType:)predicateForWorkoutActivities(operatorType:duration:)predicateForWorkoutActivities(start:end:options:)predicateForWorkoutActivities(operatorType:quantityType:averageQuantity:)predicateForWorkoutActivities(operatorType:quantityType:maximumQuantity:)predicateForWorkoutActivities(operatorType:quantityType:minimumQuantity:)predicateForWorkoutActivities(operatorType:quantityType:sumQuantity:)
Creating activity summary predicates
Creating electrocardiogram predicates
predicateForElectrocardiograms(classification:)predicateForElectrocardiograms(symptomsStatus:)predicateForObjectsAssociated(electrocardiogram:)
Creating predicate format strings
Creating sort descriptors
Type Methods
predicateForMedicationDoseEvent(medicationConceptIdentifier:)predicateForMedicationDoseEvent(medicationConceptIdentifiers:)predicateForMedicationDoseEvent(scheduledDate:)predicateForMedicationDoseEvent(scheduledDates:)predicateForMedicationDoseEvent(scheduledStart:end:)predicateForMedicationDoseEvent(status:)predicateForMedicationDoseEvent(statuses:)predicateForStatesOfMind(with:)predicateForStatesOfMind(with:)predicateForStatesOfMind(with:)predicateForStatesOfMind(withValence:operatorType:)predicateForUserAnnotatedMedications(hasSchedule:)predicateForUserAnnotatedMedications(isArchived:)predicateForWorkoutEffortSamplesRelated(workout:activity:)
See Also
Related Documentation
HKActivitySummaryQueryHKAnchoredObjectQueryHKDocumentQueryHKObserverQueryHKSourceQueryHKStatisticsQueryHKStatisticsCollectionQueryHKWorkoutRouteQuery