Xcode Swift 3定时器错误
该代码必须转换为Swift 3Xcode Swift 3定时器错误,swift,xcode,timer,Swift,Xcode,Timer,该代码必须转换为Swift 3 func checkIfCorrect (_ buttonPressed:Int) { if buttonPressed == playlist[numberOfTaps] { if numberOfTaps == playlist.count - 1 { // we have arrived at the last item of the playlist let time = Dispa
func checkIfCorrect (_ buttonPressed:Int) {
if buttonPressed == playlist[numberOfTaps] {
if numberOfTaps == playlist.count - 1 { // we have arrived at the last item of the playlist
let time = DispatchTime(uptimeNanoseconds: DispatchTime.now()) + Double(Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC)
DispatchQueue.main.asyncAfter(deadline: time, execute: {
self.nextRound()
})
return
}
代码返回一个错误,该错误表示“无法将'DispatchTime'类型的值转换为预期的参数类型UInt64”。有什么好的解决办法吗?在Swift 3中,这要容易得多 例如,从现在起一秒钟的
调度时间是:
let time : DispatchTime = .now() + .seconds(1)
这些其他装置也可用:
.millizes()
.microseconds()
.nanoseconds()
这是一个很好的例子,展示了Swift 3的表现力
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {
self.nextRound()
})