Invokes a method of the receiver on the specified thread using the specified modes.
- iOS 2.0+
- macOS 10.5+
- tvOS 9.0+
- watchOS 2.0+
A Selector that identifies the method to invoke. It should not have a significant return value and should take a single argument of type id, or no arguments.
The thread on which to execute
a. This thread represents the target thread.
The argument to pass to the method when it is invoked. Pass
nilif the method does not take an argument.
A Boolean that specifies whether the current thread blocks until after the specified selector is performed on the receiver on the specified thread. Specify
trueto block this thread; otherwise, specify
falseto have this method return immediately.
If the current thread and target thread are the same, and you specify
truefor this parameter, the selector is performed immediately. If you specify
false, this method queues the message and returns immediately, regardless of whether the threads are the same or different.
An array of strings that identifies the modes in which it is permissible to perform the specified selector. This array must contain at least one string. If you specify
nilor an empty array for this parameter, this method returns without performing the specified selector. For information about run loop modes, see Run Loops in Threading Programming Guide.
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 run loop modes specified in the
array parameter. As part of its normal run loop processing, the target thread dequeues the message (assuming it is running in one of the specified modes) and invokes the desired method.
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
perform(_: method instead.
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.