What is the significance of WaitUntilDOne
in performSelectorOnMainThread
?
IN what way the YES
or NO
set to WaitUntilDone
can have on the App?
UPDATE:
My Question should have been: In what scenarios do they make difference?
Sergio's answer was the one I was expecting.
If you say
NO
,performSelectorOnMainThread
doesn't block, and will execute the next line of code after theperformSelectorOnMainThread
immediately without waiting for the main thread to execute your selector.If you say
YES
, the thread from which you calledperformSelectorOnMainThread
will block execution at that line until the main thread has executed your selector, then it will continue.YES means the current thread blocks / waits until the selector is performed, NO to have
performSelectorOnMainThread:withObject:waitUntilDone:
returns immediatelyGenerally, you want to avoid blocking the current thread's execution using
YES
.If
NO
, the message will be added to the main thread's run loop's to do list to be performed when the run loop resumes -- that could be soon and practically immediately/concurrently.From Apple docs about
waitUntilDone
:You have to focus on which thread is executing
performSelectorOnMainThread
. That thread will block and wait until the main thread has completed that selector; say, e.g., that a worker thread needs sending a message to the main thread (e.g., to store some info to some central store which is not thread-safe). The worker might want to block and wait for the operation to complete before issuing another operation of the same kind. So,waitUntilDone
come in handy in such case.