HKWorkoutRouteQueryDescriptor
A query interface that reads the location data stored in a workout route using Swift concurrency.
Declaration
struct HKWorkoutRouteQueryDescriptorOverview
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.