我想获取HealthKit数量数据并按数量值对其进行排序。可能吗?
我知道我可以使用HKPredicateKeyPathQuantity
中的NSPredicate
来过滤它们,但我无法找到类似的排序键
示例
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)
}