错误“无法将类型为"int"的值转换为预期的参数类型为"UInt" [英] Error 'cannot convert value of type 'int' to expected argument type 'UInt'
本文介绍了错误“无法将类型为"int"的值转换为预期的参数类型为"UInt"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在线
var anchor = HKQueryAnchor(fromValue: Int(HKAnchoredObjectQueryNoAnchor))
我收到红旗错误
无法将类型"Int"的值转换为预期的参数类型"Uint"
cannot convert value of type 'Int' to expected argument type 'Uint'
我已经复制粘贴了另一个Xcode项目中的代码,该代码在另一个项目中没有给该行带来任何错误(仅在watchOS上读取心率).
I had copy-pasted the code from another Xcode project, which brought no error for this line in the other project (reading heart rate on watchOS only).
有什么想法吗?
let healthStore = HKHealthStore()
//State of the app - is the workout activated
var workoutActive = false
// define the activity type and location
var workoutSession : HKWorkoutSession?
let heartRateUnit = HKUnit(fromString: "count/min")
var anchor = HKQueryAnchor(fromValue: Int(HKAnchoredObjectQueryNoAnchor))
推荐答案
错误正在告诉您确切的操作.只需更改代码即可:
The error is telling you exactly what you have to do. Just change the code:
var anchor = HKQueryAnchor(fromValue: UInt(HKAnchoredObjectQueryNoAnchor))
您需要将UInt
更改为Int
,这是HKQueryAnchor
所期望的.
You need to change Int
for UInt
, which is what HKQueryAnchor
expects.
这篇关于错误“无法将类型为"int"的值转换为预期的参数类型为"UInt"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文