iOS
Swift

SwiftでTimer処理

More than 1 year has passed since last update.

NSTimer.scheduledTimerWithTimeIntervalを使います

NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "onTimer:", userInfo: nil, repeats: true)

func onTImer(sender:NSTimer) {
    print("on timer")
}

タイマーのハンドラに何か値を渡したい場合はuserInfoを使用します

NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "onTimer:", userInfo: "Hello", repeats: true)

func onTImer(sender:NSTimer) {
    print("\(sender.userInfo as! String)")
}