我想获取HealthKit数量数据并按数量值排序。这可能吗?
我知道我可以通过在NSPredicate
中使用HKPredicateKeyPathQuantity
来过滤它们但是我找不到类似的键来排序
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)
}
目前只能让HealthKit按日期对结果进行排序。你应该向苹果公司投诉你想要的增强功能。