---
title: HKAnchoredObjectQuery
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hkanchoredobjectquery
---

# HKAnchoredObjectQuery

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

## Declaration

```swift
class HKAnchoredObjectQuery
```

## Mentioned in

About the HealthKit framework Executing Observer Queries Receiving Downhill Skiing and Snowboarding Data

## Overview

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

## Topics

### Creating Anchored Object Queries

- [Executing Anchored Object Queries](healthkit/executing-anchored-object-queries.md)
- [init(type:predicate:anchor:limit:resultsHandler:)](healthkit/hkanchoredobjectquery/init(type:predicate:anchor:limit:resultshandler:).md)
- [init(queryDescriptors:anchor:limit:resultsHandler:)](healthkit/hkanchoredobjectquery/init(querydescriptors:anchor:limit:resultshandler:).md)
- [HKObjectQueryNoLimit](healthkit/hkobjectquerynolimit.md)
- [init(type:predicate:anchor:limit:completionHandler:)](healthkit/hkanchoredobjectquery/init(type:predicate:anchor:limit:completionhandler:).md)

### Receiving Updates

- [updateHandler](healthkit/hkanchoredobjectquery/updatehandler.md)

### Tracking Anchors

- [HKQueryAnchor](healthkit/hkqueryanchor.md)

### Tracking Deleted Objects

- [HKDeletedObject](healthkit/hkdeletedobject.md)

## Relationships

### Inherits From

- [HKQuery](healthkit/hkquery.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Long-running queries

- [HKActivitySummaryQueryDescriptor](healthkit/hkactivitysummaryquerydescriptor.md)
- [HKActivitySummaryQuery](healthkit/hkactivitysummaryquery.md)
- [HKAnchoredObjectQueryDescriptor](healthkit/hkanchoredobjectquerydescriptor.md)
- [HKObserverQuery](healthkit/hkobserverquery.md)
