Query health and fitness data.


Use queries to read sample data from the HealthKit store. Queries can also be used to list all the sources for a particular type of data, or to do statistical calculations. For example, statistical queries can calculate the minimum and maximum heartrate for a given week, or the total step count for a given day.

You run a query by calling the HealthKit store’s executeQuery: method. A snapshot of the current results are asynchronously returned to the query’s results handler. Long-running queries continue to monitor the HealthKit store, and return any relevant changes to the query’s update handler. To return sorted or filtered results, give the query a sort descriptor or predicate.


First Steps

Reading Data from HealthKit

Use queries to request sample data from HealthKit.

Common Query Types


A general query that returns a snapshot of all the matching samples currently saved in the HealthKit store.


A query that accesses the series data associated with a quantity sample.


A query that returns changes to the HealthKit store, including a snapshot of new changes and continuous monitoring as a long-running query.


A long-running query that monitors the HealthKit store and updates your app when the HealthKit store saves or deletes a matching sample.


A query that performs complex searches based on the correlation’s contents, and returns a snapshot of all matching samples.


A query that returns a snapshot of all matching documents currently saved in the HealthKit store.


A query that returns the heartbeat data contained in a heartbeat series sample.


An abstract class for all the query classes in HealthKit.

Sources and Devices


An object indicating the source of a HealthKit sample.


An object indicating the app or device that created a HealthKit sample


A device that generates data for HealthKit.


A query that returns a list of sources, such as apps and devices, that have saved matching queries to the HealthKit store.

Calculating Statistics


A query that performs statistical calculations over a set of matching quantity samples, and returns the results.


A query that performs multiple statistics queries over a series of fixed-length time intervals, and returns the results.


An object that represents the result of calculating the minimum, maximum, average, or sum over a set of samples from the HealthKit store.


An object that manages a collection of statistics; each statistics object represents the data calculated over a separate time interval.


Options for specifying the statistic to calculate.

See Also

Health Data

Saving Data to HealthKit

Create and share HealthKit samples.

Reading Data from HealthKit

Use queries to request sample data from HealthKit.

Data Types

Specify the kind of data used in HealthKit.


Create and save health and fitness samples.