Error 'cannot convert value of type 'int' to expected argument type 'UInt'

孤街浪徒 提交于 2020-01-07 07:44:14

问题


On the line

var anchor = HKQueryAnchor(fromValue: Int(HKAnchoredObjectQueryNoAnchor))

I get the red flag error

cannot convert value of type 'Int' to expected argument type 'Uint'

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).

Any ideas?

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))

回答1:


The error is telling you exactly what you have to do. Just change the code:

var anchor = HKQueryAnchor(fromValue: UInt(HKAnchoredObjectQueryNoAnchor))

You need to change Int for UInt, which is what HKQueryAnchor expects.



来源:https://stackoverflow.com/questions/38663875/error-cannot-convert-value-of-type-int-to-expected-argument-type-uint

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!