我想获取 HealthKit 数量数据并按数量值对它们进行排序。可能吗?
我知道我可以使用HKPredicateKeyPathQuantity
in过滤它们,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)
}