Last active
January 31, 2022 08:30
-
-
Save tshortli/e6f0dc0405a61884c99147576de96c9b to your computer and use it in GitHub Desktop.
A Swift async function that gets the most recent workouts from HealthKit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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