---
title: HKObserverQuery
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/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.

## Declaration

```swift
class HKObserverQuery
```

## Mentioned in

Reading data from HealthKit

## Overview

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

- [Executing Observer Queries](healthkit/executing-observer-queries.md)
- [init(sampleType:predicate:updateHandler:)](healthkit/hkobserverquery/init(sampletype:predicate:updatehandler:).md)
- [init(queryDescriptors:updateHandler:)](healthkit/hkobserverquery/init(querydescriptors:updatehandler:).md)
- [HKObserverQueryCompletionHandler](healthkit/hkobserverquerycompletionhandler.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)
- [HKAnchoredObjectQuery](healthkit/hkanchoredobjectquery.md)
