Last active
February 8, 2022 15:29
-
-
Save aokj4ck/e4f048d4e2212fbf7e3d5d7dc299e5e0 to your computer and use it in GitHub Desktop.
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
// Construct startDate and endDate objects with NSDateComponents. | |
// See this article for more http://iaintheindie.com/2014/08/08/useful-nsdate-nscalendar-tricks/#StartEnd_of_the_Week | |
// For more examples of working with HealthKit see https://developer.apple.com/library/content/samplecode/Fit/Introduction/Intro.html | |
let workoutPredicate = NSPredicate(format: "(%K == %d) OR (%K == %d)", | |
HKPredicateKeyPathWorkoutType, | |
HKWorkoutActivityType.functionalStrengthTraining.rawValue, | |
HKPredicateKeyPathWorkoutType, | |
HKWorkoutActivityType.traditionalStrengthTraining.rawValue) | |
let timePredicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: []) | |
let combinedPredicate = NSCompoundPredicate.init(andPredicateWithSubpredicates: [workoutPredicate, timePredicate]) | |
let query = HKSampleQuery(sampleType: HKSampleType.workoutType(), predicate: combinedPredicate, limit: limitless, sortDescriptors: nil) {…} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment