gpt4 book ai didi

swift - 错误 'cannot convert value of type ' int' 到预期参数类型 'UInt'

转载 作者:行者123 更新时间:2023-11-28 16:19:24 27 4
gpt4 key购买 nike

在线

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

我得到红旗错误

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

我从另一个 Xcode 项目复制粘贴了代码,这在另一个项目中没有为这一行带来错误(仅在 watchOS 上读取心率)。

有什么想法吗?

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

最佳答案

错误是告诉你你必须做什么。只需更改代码:

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

您需要将 Int 更改为 UInt,这是 HKQueryAnchor 所期望的。

关于swift - 错误 'cannot convert value of type ' int' 到预期参数类型 'UInt',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38663875/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com