LoginSignup
3
3

More than 5 years have passed since last update.

swift playgroundでNSTimerを使う

Last updated at Posted at 2016-02-22

swift playgroundでNSTimerを使う方法を記載

playgroundの実行はそのままだと終了してしまうので、
XCPlaygroundPage.currentPage.needsIndefiniteExecutionをtrueに設定して永続するようにします。


import UIKit
import XCPlayground

XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

class timerController:NSTimer {

    func setTimer() {
        let _fps = round(1000/30)*0.001;
        NSTimer.scheduledTimerWithTimeInterval(_fps, target: self, selector: Selector("ticker"), userInfo: nil, repeats: true)
    }

    func ticker() {
        print("hoge")
    }

}

var obj:timerController = timerController();
obj.setTimer()

以上

3
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3