Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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