gpt4 book ai didi

swift - 错误: Cannot convert value of type 'UInt64' to expected argument type 'DispatchTime'

转载 作者:行者123 更新时间:2023-11-30 12:08:14 31 4
gpt4 key购买 nike

我试图在 Swift4 中创建一个由变量控制的计时器,唯一的问题是我收到错误:

Cannot convert value of type 'UInt64' to expected argument type 'DispatchTime'

这是代码:

let maxNumber = maxNumberField.intValue
let amountOfNumbers = amountOfNumbersField.intValue
var delay = 5
var x: Int32 = amountOfNumbers

while(x > 0){

let when = (DispatchTime.now().uptimeNanoseconds + (5 * UInt64(x)))
DispatchQueue.main.asyncAfter(deadline: when) { // error

let number = arc4random_uniform(UInt32(maxNumber + 1))
let synth = NSSpeechSynthesizer()
synth.startSpeaking(String(number))
}
x = (x - 1)
}

根据我的理解,我需要将 when 变量(UInt64)转换为 DispatchTime

我该怎么做?

最佳答案

您应该:

关于swift - 错误: Cannot convert value of type 'UInt64' to expected argument type 'DispatchTime' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46409400/

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