2017-02-21 71 views
0

我想從查詢中提取血糖值,以查看我在健康應用程序中獲取的最後10個血糖值。我能夠從健康的應用程序提取數據,並把它的形式爲一個條目:從HealthKit獲取血糖查詢

(2017-02-21 13:13:00 -0500 - 2017-02-21 13:13:00 -0500), 80 mg/dL 52D7A973-7853-455C-9308-0E339153A3BE "Health" (10.2.1) metadata: { 
HKWasUserEntered = 1;} 

我能夠拉從這個開始日期(日期和結束日期)加入:

guard let timing = reading?.endDate as Date? else { 
       print("timing scheme didn't work.") 
       return 
      } 

print(timing) 

並通過寫入

guard let bg = reading?.sampleType as HKSampleType? else { 
       print("bg scheme didn't work") 
       return 
      } 

print(bg) 

然而拉型(HKQuantityTypeIdentifierBloodGlucose),我不能找出打印的實際血葡萄糖值(即,80毫克/分升)。

我想:

let bg = reading.quantity 

,但我得到了錯誤

Value of type 'Optional<HKSample>' has no member 'quantity' 

如果任何人有深入瞭解這一點,那將是非常有幫助的!先謝謝你!

回答

0
// To read blood glucose: 
      let gluco = reading as? HKQuantitySample 
      if let bg = gluco?.quantity { 
       print(bg) 
      }