<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SensorKit",
  "identifier" : "/documentation/SensorKit/SRReader/samples(matching:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SensorKit"
    ],
    "preciseIdentifier" : "s:9SensorKit8SRReaderC7samples8matchingQrSo14SRFetchRequestC_tF"
  },
  "title" : "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.

```
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

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

## 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

```swift
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.

---

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)