[英]How to create an HKQuantitySample from HKStatistics?
我试图过程HKStatistics
是心脏速率,并创建一个HKQuantitySample
,这样我可以追加到本地阵列。 我不知道用于startDate
和endDate
日期,目前我只是使用Date()
但我宁愿更精确并使用实际样本的日期。 statistics.StartDate
只为您提供统计数据收集开始的日期,而不是单个样本/统计数据的日期。 我看到统计数据也有一个mostRecentQuantityDateInterval()
属性,但不知道如何在这里使用它。
private func processStatistics(withStatistics statistics: HKStatistics?) {
// Make sure we got non `nil` parameters.
guard let statistics = statistics else {
fatalError("no statistics in processStatistics")
}
// Dispatch to main, because we are updating the interface.
DispatchQueue.main.async {
switch statistics.quantityType {
case HKQuantityType.quantityType(forIdentifier: .heartRate):
if let unwrappedQuantity = statistics.mostRecentQuantity() {
let statisticAsHKQuantitySample = HKQuantitySample(type: statistics.quantityType, quantity: unwrappedQuantity, start: Date(), end: Date())
self.heartRateSamples.append(statisticAsHKQuantitySample)
}
我认为您正在寻找: mostRecentQuantityDateInterval()
let interval = statistics.mostRecentQuantityDateInterval()
interval.start
interval.end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.