Contents

HKWorkoutRouteQueryDescriptor

A query interface that reads the location data stored in a workout route using Swift concurrency.

Declaration

struct HKWorkoutRouteQueryDescriptor

Overview

Use HKWorkoutRouteQueryDescriptor to access the individual CLLocation objects stored in an HKWorkoutRoute sample. To read the individual locations, create a workout route query descriptor using the desired route, and then call the descriptor’s results(for:) method.

// Create the descriptor.
let routeQueryDescriptor = HKWorkoutRouteQueryDescriptor(myRoute)

// Get the AsyncSequence that returns individual locations.
let locations = routeQueryDescriptor.results(for: store)

// Access each location.
for try await location in locations {
    
    // Process the results here.
    print(location.coordinate)
    print(location.timestamp)
}

While this method returns an AsyncSequence, unlike the long-running queries, this sequence has a finite size. Iterating over the sequence asynchronously returns the route’s locations, automatically terminating after you receive all the locations.

Topics

Creating workout route query descriptors

Running queries

Accessing query properties

Default Implementations

See Also

Series queries