6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swift4でTimerを使う

Posted at

5秒ごとにHelloと出力します。

Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) {_ in
    print("Hello")
}

従来のselectorを使った方法だと、対象のメソッドに @objc キーワードを付ける必要がありますが、このキーワード自体、4から非推奨になったようでビルド時に警告が出てしまいます。動くことは動きますが、今後はこちらの書き方に統一していった方が良さそうです。

参考(DispatchQueue):
https://qiita.com/lumbermill/items/7553a6ace26019f08bc6

6
3
0

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
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?