What is the difference between using this
[self performSelectorOnMainThread:@selector(doStuff:)
withObject:myObject
waitUntilDone:YES];
instead of simply
[self doStuff:myObject];
in terms of CPU load? Or there are any other advantages?
thanks.
This makes sure that the selector is performed on the main thread by adding it to the main run loop. When you set
waitUntilDone:YES, you will let your current thread idle as long as the main run loop needs to perform the selector.In a single threaded environment this will let the runloop run right after you called this, in a multithreaded environment, the main runloop will perform the selector once it does the next step.
You have in any of the both cases a small overhead as the selector isn’t performed right after you called the function but at a later point while
[self doStuff:myObject];performs the selector immediately