LoginSignup
5
5

More than 5 years have passed since last update.

NSTimerのtoleranceプロパティ

Last updated at Posted at 2015-03-26

NSTimerのリファレンスを見ていたらtoleranceという見慣れないプロパティが追加されていた。
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/#//apple_ref/occ/instp/NSTimer/tolerance

iOS7以降で使える模様。

toleranceには寛容とか許容という意味がある。

要するにタイマーをリピートさせるときの次回発火時間を計算する際にtoleranceプロパティを加味して計算するということらしい。そして、toleranceプロパティには経験則として少なくともintervalの 10% を与えてあげると良いとのこと。

NSTimeInterval timeInterval = 1.0;
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(updateData:) userInfo:nil repeats:YES];
timer.tolerance = timeInterval * (10.0 / 100.0);

設定した場合としなかった場合とで比較できてないけれど、基本的に設定しておくのが吉な気がする。

5
5
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
5
5