Contents

HKQuery

An abstract class for all the query classes in HealthKit.

Declaration

class HKQuery

Mentioned 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

Creating sample predicates

Creating quantity sample predicates

Creating category sample predicates

Creating clinical record predicates

Creating workout predicates

Creating workout activity predicates

Creating activity summary predicates

Creating electrocardiogram predicates

Creating predicate format strings

Creating sort descriptors

Type Methods

See Also

Related Documentation

Basic queries