[英]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.