Search code examples
xcodefunctionswiftdelaynstimer

Creating a Neat delay function using NSTimer - Swift


I am trying to create a simple and neat function that uses NSTimer to add a delay to what is ever in the brackets. For e.g.

 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)
    }

From this, i am trying to aim to use it by going:

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

The function NEEDS to use NSTimer for what i am using it for as a whole.

Any help will be greatly appreciated.


Solution

  • in your case, you need to use extension for NSTimer. Published on gist: https://gist.github.com/dimpiax/e2adc74c25d76d124fc3

    Update:

    Published lib: https://github.com/dimpiax/RichTimer