Initializer

init(timeInterval:target:selector:userInfo:repeats:)

Initializes a timer object with the specified object and selector. あるタイマーオブジェクトをこの指定されたオブジェクトとセレクタで初期化します。

Declaration 宣言

init(timeInterval ti: TimeInterval, 
target aTarget: Any, 
selector aSelector: Selector, 
userInfo: Any?, 
repeats yesOrNo: Bool)

Parameters パラメータ

ti

The number of seconds between firings of the timer. If ti is less than or equal to 0.0, this method chooses the nonnegative value of 0.0001 seconds instead. タイマーの発火それらの間の秒数。ti0.0より少ないまたは等しいならば、このメソッドは代わりに0.0001秒の非負の値を選びます。

target

The object to which to send the message specified by aSelector when the timer fires. The timer maintains a strong reference to this object until it (the timer) is invalidated. タイマーが発火する場合このオブジェクトに対してaSelectorによって指定されたメッセージを送ります。タイマーは、このオブジェクトに対する強い参照を、それ(タイマー)が無効にされるまで保守します。

aSelector

The message to send to target when the timer fires. タイマーが発火する場合targetに送ることになるメッセージ。

The selector should have the following signature: timerFireMethod: (including a colon to indicate that the method takes an argument). The timer passes itself as the argument, thus the method would adopt the following pattern: セレクタは以下のシグネチャを持つべきです:timerFireMethod:(メソッドがひとつの引数を取ることを指し示すコロンを含みます)。タイマーは、それ自身を引数として渡します、したがってメソッドは以下のパターンを採用するでしょう:


- (void)timerFireMethod:(NSTimer *)timer
userInfo

Custom user info for the timer. タイマーに対するあつらえのユーザ情報。

The timer maintains a strong reference to this object until it (the timer) is invalidated. This parameter may be nil. タイマーは、このオブジェクトに対する強い参照を、それ(タイマー)が無効にされるまで保守します。このパラメータはnilであるかもしれません。

repeats

If true, the timer will repeatedly reschedule itself until invalidated. If false, the timer will be invalidated after it fires. trueならば、タイマーは、無効にされるまで繰り返しそれ自身を予定します。falseならば、タイマーはそれが発火した後に無効にされます。

Return Value 戻り値

A new NSTimer object, configured according to the specified parameters. ある新しいNSTimerオブジェクト、それは指定されたパラメータによって構成設定されます。

Discussion 議論

You must add the new timer to a run loop, using add(_:forMode:). Then, after ti seconds have elapsed, the timer fires, sending the message aSelector to target. (If the timer is configured to repeat, there is no need to subsequently re-add the timer to the run loop.) あなたは、この新しいタイマーを実行ループに、add(_:forMode:)を使って加えなければなりません。それから、ti秒が経過した後に、タイマーは発火して、メッセージaSelectortargetに送信します。(タイマーが繰り返すように構成設定されるならば、続けてタイマーを実行ループへと再度追加する必要はありません。)

See Also 参照

Creating a Timer タイマーを作成する