JOSEFtw JOSEFtw - 2 months ago 8
Swift Question

Do something every x minutes in Swift

How can I run a function every minute?
In JavaScript I can do something like

setInterval
, does something similar exist in Swift?

Wanted output:

Hello World once a minute...

Answer
var helloWorldTimer = NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: Selector("sayHello"), userInfo: nil, repeats: true)

func sayHello() 
{
    NSLog("hello World")
}

Remember to import Foundation.

Comments