【问题标题】:Cannot convert value type "" to expected argument 'UInt64'无法将值类型“”转换为预期的参数“UInt64”
【发布时间】:2017-03-17 18:51:33
【问题描述】:

我在从 Swift 2 转换到 Swift 3 后立即使用了这段代码,然后出现了这个错误消息。任何帮助将不胜感激。我对 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 = DispatchTime(uptimeNanoseconds: DispatchTime.now()) + Double(Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC)

            DispatchQueue.main.asyncAfter(deadline: time, execute: { 
                    self.nextRound()
            })

            return
        }

        numberOfTaps += 1
    }else{ // GAME OVER
        resetGame()
    }
}

【问题讨论】:

  • 完整的错误是什么?哪一行导致错误?

标签: swift swift3


【解决方案1】:

你有这个:

let time = DispatchTime(uptimeNanoseconds: DispatchTime.now()) + Double(Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC)

这样写:

let time = DispatchTime.now() + 1.0 // or however long you want the delay to be

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-17
    • 2016-03-21
    • 2016-07-27
    • 2016-07-02
    • 1970-01-01
    • 2021-04-18
    • 2020-03-01
    • 2016-08-01
    相关资源
    最近更新 更多