0

我想获取 HealthKit 数量数据并按数量值对它们进行排序。可能吗?

我知道我可以使用HKPredicateKeyPathQuantityin过滤它们,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)

}
4

1 回答 1

1

目前只能让 HealthKit 按日期对结果进行排序。您应该向 Apple提交一个错误,以获得您想要的增强功能。

于 2015-07-29T18:13:08.917 回答