使用 NSTimer 创建 Neat 延迟函数 - Swift

Creating a Neat delay function using NSTimer - Swift

我正在尝试创建一个简单而巧妙的函数,它使用 NSTimer 为括号中的内容添加延迟。例如

 func Adddelay(delay:Double, closure:()->()) {
  //Code in here using NSTimer that will add a delay for as long as stated in delay (the number passed in)
    }

由此,我试图通过以下方式使用它:

delay(1){
//Code in here that will execute after a delay of one second
}     

函数需要将 NSTimer 用于我正在使用它的整体。

任何帮助将不胜感激。

在你的情况下,你需要使用 NSTimer 的扩展。发表在要点上:https://gist.github.com/dimpiax/e2adc74c25d76d124fc3

更新:

已发布的库:https://github.com/dimpiax/RichTimer