I want to fetch HealthKit quantity data and sort them by quantity value. Is it possible?
I know I can filter them by using HKPredicateKeyPathQuantity
in the NSPredicate
but I can't find similar key for sorting
Example
let type = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight)
let sort = [
NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: true),
NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: true),
//I want one more Sort Item here :(
//NSSortDescriptor(key: SortIdentifierIdeQuantity, ascending: true)
]
let predicate = NSPredicate(format: "\(HKPredicateKeyPathStartDate) > %@ AND \(HKPredicateKeyPathStartDate) < %@ AND \(HKPredicateKeyPathQuantity) == %@",
argumentArray:[start, end, value])
let query = HKSampleQuery(sampleType: type, predicate: predicate, limit: limit, sortDescriptors: sort) { query, res, error in
completion(res, error)
}
healthKit.executeQuery(query)
}