<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKAnchoredObjectQuery",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKAnchoredObjectQuery"
  },
  "title" : "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.

```
class HKAnchoredObjectQuery
```

## Overview

Anchored object queries provide an easy way to search for new data in the HealthKit store. An [`HKAnchoredObjectQuery`](/documentation/HealthKit/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`](/documentation/HealthKit/HKAnchoredObjectQuery/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`](/documentation/HealthKit/HKSampleQuery)).
- It can also perform a long-running query that responds to updates (like an [`HKObserverQuery`](/documentation/HealthKit/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

  <doc://com.apple.healthkit/documentation/HealthKit/executing-anchored-object-queries>

[`-  initWithType:predicate:anchor:limit:resultsHandler:`](/documentation/HealthKit/HKAnchoredObjectQuery/init(type:predicate:anchor:limit:resultsHandler:))

Initializes a new anchored object query.

[`-  initWithQueryDescriptors:anchor:limit:resultsHandler:`](/documentation/HealthKit/HKAnchoredObjectQuery/init(queryDescriptors:anchor:limit:resultsHandler:))

Creates an anchored object query that matches any of the query descriptors you provided.

[`HKObjectQueryNoLimit`](/documentation/HealthKit/HKObjectQueryNoLimit)

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

[`-  initWithType:predicate:anchor:limit:completionHandler:`](/documentation/HealthKit/HKAnchoredObjectQuery/init(type:predicate:anchor:limit:completionHandler:))

Initializes a new anchored object query.

### Receiving Updates

[`updateHandler`](/documentation/HealthKit/HKAnchoredObjectQuery/updateHandler)

Handler for monitoring updates to the HealthKit store.

### Tracking Anchors

[`HKQueryAnchor`](/documentation/HealthKit/HKQueryAnchor)

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

### Tracking Deleted Objects

[`HKDeletedObject`](/documentation/HealthKit/HKDeletedObject)

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

## Relationships

### Inherits From

[`HKQuery`](/documentation/HealthKit/HKQuery)

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Sendable`](/documentation/Swift/Sendable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)