Class

HKSampleQuery

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

Declaration

@interface HKSampleQuery : HKQuery

Overview

You can use sample queries to search for any concrete subclasses of the HKSample class, including HKCategorySample, HKCorrelation, HKQuantitySample, and HKWorkout objects.

The sample query returns sample objects that match the provided type and predicate. You can provide a sort order for the returned samples, or limit the number of samples returned. Other query classes can be used to perform more specialized searches and calculations. For more information, see HKQuery.

Sample queries are immutable: The query’s properties are set when the query is first created, and they can't change.

Topics

Creating Sample Queries

Executing Sample Queries

Create, run, and sort sample queries.

HKObjectQueryNoLimit

A value indicating that the query returns all the matching samples in the HealthKit store.

HealthKit Sort Descriptors

Identifiers for sorting results.

Getting Property Data

limit

The maximum number of samples that this query returns.

sortDescriptors

The sort descriptors that specify the order of the results returned by this query.

Setting Limits

HKObjectQueryNoLimit

A value indicating that the query returns all the matching samples in the HealthKit store.

Relationships

Inherits From

See Also

Common Query Types

HKQuantitySeriesSampleQuery

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

HKAnchoredObjectQuery

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

HKObserverQuery

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

HKCorrelationQuery

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

HKDocumentQuery

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

HKHeartbeatSeriesQuery

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

HKQuery

An abstract class for all the query classes in HealthKit.