Dimitri T Dimitri T - 1 year ago 53
Swift Question

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

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download