简体   繁体   English

Swift Heart Rate可变性结果从ms转换为double

[英]Swift Heart Rate Variability result conversion from ms to double

So I'm trying to make an app where the user's heart rate variability is fetched and displayed to them. 所以我正在尝试创建一个应用程序,用户的心率变异性被提取并显示给他们。 The issue is that Im not really sure how to convert the result I get from my query to a double, I have tried using 问题是,我不确定如何将我从查询中获得的结果转换为double,我尝试过使用

let quantity: HKQuantity? = result?.averageQuantity()
beats = quantity?.doubleValue(for: HKUnit.count().unitDivided(by: HKUnit.minute()))
print(beats)

but I would get the error "reason: 'Attempt to convert incompatible units: ms, count/min'" which is expected because the beats line is intended for average heart rate not heart rate variability. 但我会得到错误“原因:'尝试转换不兼容的单位:ms,count / min'”这是预期的,因为beats line用于平均心率而不是心率变异性。 If i print out the quantity variable I do get the result back in this format "Optional(65.24 ms)". 如果我打印出数量变量,我会以“可选(65.24毫秒)”格式返回结果。

My question is how do I properly convert the result from the first line from ms to a double? 我的问题是如何正确地将第一行的结果从ms转换为double? Or how can i display it on a label? 或者我如何在标签上显示它? Because in the ms form it won't work. 因为在ms形式它不会工作。

Thank for the help in advance guys 感谢提前帮助的人

Found a solution. 找到了解决方案。 This is how to convert the heart rate variability result from MS to a double value. 这是如何将心率变异性结果从MS转换为双倍值。 You can then change it to a string 然后,您可以将其更改为字符串

beats = quantity?.doubleValue(for: HKUnit.secondUnit(with: .milli))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM