<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKObserverQuery",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKObserverQuery"
  },
  "title" : "HKObserverQuery"
}
-->

# HKObserverQuery

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

```
class HKObserverQuery
```

## Overview

Observer queries set up a long-running task on a background queue. This task watches the HealthKit store, and alerts you when the store saves or removes matching data. Your app uses observer queries to respond to changes made by other apps and devices.

> Important:
> Background server queries aren’t supported on the Simulator. Be sure to test your background queries on a device.

Observer queries are immutable: You set their properties when you first create them, and you can’t change them.

## Topics

### Creating Observer Queries

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

[`-  initWithSampleType:predicate:updateHandler:`](/documentation/HealthKit/HKObserverQuery/init(sampleType:predicate:updateHandler:))

Instantiates and returns a query that monitors the HealthKit store and responds to changes.

[`-  initWithQueryDescriptors:updateHandler:`](/documentation/HealthKit/HKObserverQuery/init(queryDescriptors:updateHandler:))

Creates a query that monitors the HealthKit store and responds to any changes matching any of the query descriptors you provided.

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

The completion handler for background deliveries.

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

### Inherits From

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

---

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)