Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wb-towa/eb457b2567a0fba5bc51e0f41ab70dee to your computer and use it in GitHub Desktop.
Save wb-towa/eb457b2567a0fba5bc51e0f41ab70dee to your computer and use it in GitHub Desktop.
A Swift async function that gets the most recent workouts from HealthKit
func mostRecentWorkouts(for healthStore: HKHealthStore, limit: Int) async throws -> [HKWorkout] {
let query = HKSampleQueryDescriptor(
predicates: [.workout()],
sortDescriptors: [SortDescriptor(\.endDate, order: .reverse)],
limit: limit
)
return try await query.result(for: healthStore)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment