---
title: "samples(matching:)"
framework: SensorKit
role: symbol
role_heading: Instance Method
platforms: [iOS 27.0+, iPadOS 27.0+, Mac Catalyst 27.0+]
path: "sensorkit/srreader/samples(matching:)"
---

# samples(matching:)

Fetches sensor data based on the provided request parameters. The reader must be authorized for the sensor for this to succeed.

## Declaration

```swift
final func samples(matching request: SRFetchRequest) -> some AsyncSequence<SRFetchResponse<Sensor.Sample>, any Error>

```

## Parameters

- `request`: An SRFetchRequest specifying the data range, filters, and other fetch parameters

## Return Value

Return Value An AsyncSequence that yields SRFetchResponse<Sensor.Sample> objects containing the sensor-specific data

## Discussion

Discussion Creates an asynchronous stream of sensor data responses. The stream continues to yield data until the fetch request is complete, an error occurs, or the stream is cancelled. Example for try await response in reader.samples(matching: request) {     // Process each data sample     switch response.sample {     case .success(let sample):         print("Sample data: \(sample)")     case .failure(let error):         print("Failed to decode sample: \(error)")     }

print("Timestamp: \(response.timestamp)") } Cancellation The stream can be cancelled by breaking out of the iteration loop or by the system when the reader is deallocated. Cancellation stops the fetch operation gracefully.
