ios - Do something every x minutes in Swift -
how can run function every minute? in javascript can setinterval
, similar exist in swift?
wanted output:
hello world once minute...
var helloworldtimer = nstimer.scheduledtimerwithtimeinterval(60.0, target: self, selector: selector("sayhello"), userinfo: nil, repeats: true) func sayhello() { nslog("hello world") }
remember import foundation.
swift 3:
var helloworldtimer = timer.scheduledtimer(timeinterval: 60.0, target: self, selector: #selector(viewcontroller.sayhello), userinfo: nil, repeats: true) func sayhello() { nslog("hello world") }
Comments
Post a Comment