An abstract class for all the query classes in HealthKit.
SDKs
- iOS 8.0+
- Mac Catalyst 13.0+
- watchOS 2.0+
Framework
- Health
Kit
Declaration
@interface HKQuery : NSObject
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.
Queries and 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 predicate is performed by the store, it restricts the number of HealthKit objects that are instantiated and returned.
Since the predicates are executed by the store, you are limited in the type of predicates that you can use. Specifically, HealthKit provides a number of predicate key paths (for example,
HKPredicate
andKey Path UUID HKPredicate
). You can create predicates using only these key paths.Key Path Metadata