按数量

时间:2015-07-29 14:11:20

标签: ios swift health-kit hksamplequery

我想获取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)

}

1 个答案:

答案 0 :(得分:1)

只能让HealthKit按日期对结果进行排序。你应该file a bug与Apple一起进行你想要的增强。