2016-11-22 41 views
1

此代码必须被转换为斯威夫特3.Xcode的斯威夫特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 
      } 

代码返回,说:“无法将类型的价值‘DispatchTime’预期参数类型UINT64”错误。这将是一个很好的解决办法?

回答

1

在斯威夫特3,它更容易

例如第二,从现在DispatchTime是:

let time : DispatchTime = .now() + .seconds(1) 

这些其他单位可供选择,太:

  • .milliseconds()
  • .microseconds()
  • .nanoseconds()
0

这是Swift 3表现力的一个很好的例子。

DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: { 
        self.nextRound() 
      })