Instance Method インスタンスメソッド

performSelector:onThread:withObject:waitUntilDone:

Invokes a method of the receiver on the specified thread using the default mode. レシーバのメソッドを指定スレッド上で省略時のモードを使って発動します。

Declaration 宣言

- (void)performSelector:(SEL)aSelector 
               onThread:(NSThread *)thr 
             withObject:(id)arg 
          waitUntilDone:(BOOL)wait;

Parameters パラメータ

aSelector

A Selector that identifies the method to invoke. The method should not have a significant return value and should take a single argument of type id, or no arguments.

thread

The thread on which to execute aSelector.

arg

The argument to pass to the method when it is invoked. メソッドに、それが発動されるときに渡される引数。 Pass nil if the method does not take an argument.

wait

A Boolean that specifies whether the current thread blocks until after the specified selector is performed on the receiver on the specified thread. 指定されたスレッドのレシーバで指定されたセレクタが実行される後まで現在のスレッドを封鎖するかどうかを指定するブール。 Specify YES to block this thread; otherwise, specify NO to have this method return immediately.

If the current thread and target thread are the same, and you specify YES for this parameter, the selector is performed immediately on the current thread. If you specify NO, this method queues the message on the thread’s run loop and returns, just like it does for other threads. The current thread must then dequeue and process the message when it has an opportunity to do so. そうでなければその実行はキューに加えられ実行ループによって次の機会に実行されます。

Discussion 解説

You can use this method to deliver messages to other threads in your application. The message in this case is a method of the current object that you want to execute on the target thread. あなたは、このメソッドを使って様々なメッセージをあなたのアプリケーションの別のスレッドに届けることができます。この場合におけるメッセージは、現在のオブジェクトのメソッドです、それはあなたが目標のスレッド上で実行するのを望むものです。

This method queues the message on the run loop of the target thread using the default run loop modes—that is, the modes associated with the NSRunLoopCommonModes constant. As part of its normal run loop processing, the target thread dequeues the message (assuming it is running in one of the default run loop modes) and invokes the desired method. それの標準的な実行ループ処理の一部として、目標のスレッドはメッセージを(それが省略時の実行ループモードの1つで実行されていると仮定して)デキューして、要望されたメソッドを発動します。

You cannot cancel messages queued using this method. あなたは、このメソッドを使ってキューされたメッセージをキャンセルできません。 If you want the option of canceling a message on the current thread, you must use either the performSelector:withObject:afterDelay: or performSelector:withObject:afterDelay:inModes: method.

Special Considerations 特別な注意事項

This method registers with the runloop of its current context, and depends on that runloop being run on a regular basis to perform correctly. One common context where you might call this method and end up registering with a runloop that is not automatically run on a regular basis is when being invoked by a dispatch queue. このメソッドは、それの現在の文脈の実行ループに登録します、そしてその実行ループが通常の原則上で動かされて正しく成し遂げられることをあてにします。あなたがこのメソッドを呼び出して自動的には通常の原則上で動かされない実行ループに登録することに終わるかもしれないよくある文脈は、ディスパッチキューによって発動されている時です。 If you need this type of functionality when running on a dispatch queue, you should use dispatch_after and related methods to get the behavior you want.

See Also 参照

Sending Messages メッセージ送信