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


@interface HKAnchoredObjectQuery : HKQuery


Anchored object queries provide an easy way to search for new data in the HealthKit store. An HKAnchoredObjectQuery returns an anchor value that corresponds to the last sample or deleted object received by that query. Subsequent queries can use this anchor to restrict their results to only newer saved or deleted objects.

Anchored object queries are mostly immutable. You can assign the query’s updateHandler property after instantiating the object, but you must set all other properties when you instantiate the object. You can’t change them.

Combine Snapshots and Updates

The anchored object query can combine the abilities of a regular query with a long-running query.

  • It grabs a snapshot of the data currently stored in the HealthKit store (like an HKSampleQuery).

  • It can also perform a long-running query that responds to updates (like an HKObserverQuery).

Often, it’s more efficient to set up and run a single anchored object query than to run separate sample and observer queries. As a result, you may want to use anchored object queries, even when you aren’t using anchors to limit the results. In this case, set the anchor parameter to nil.


Creating Anchored Object Queries

Executing Anchored Object Queries

Create and run an anchored object query.

- initWithType:predicate:anchor:limit:resultsHandler:

Initializes a new anchored object query.


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

- initWithType:predicate:anchor:limit:completionHandler:

Initializes a new anchored object query.


Receiving Updates


Handler for monitoring updates to the HealthKit store.

Tracking Anchors


An object used to identify all the samples previously returned by an anchored object query.

Tracking Deleted Objects


An object that represents a sample that has been deleted from the HealthKit store.


Inherits From

See Also

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 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.