You should not use NSTimer
at this time. It consumes a lot of resources, leads to unnecessary battery drain, and the API lends itself to ugly code.
Use dispatch_after()
instead:
dispatch_after(0, dispatch_get_main_queue()) { () -> Void in for counter in 0...1000 { var b = counter } }
Of course, since the timer will fire after the playground has loaded, you will need the equivalent of timer.fire()
to force the code to execute immediately, and not after a 0-second delay. Here's how it works:
let printFrom1To1000 = { () -> Void in for counter in 0...1000 { var b = counter } } dispatch_after(0, dispatch_get_main_queue(), printFrom1To1000) printFrom1To1000()
source share