Saturday, August 15, 2015

Dispatch Async to Main Queue and Modal Windows

Kirby Turner:

Instead of dispatching the completion() to the main queue, I call it directly from the background thread. In the completion block itself, I decide how to get the code should run in the main thread. If my window isn’t modal, then I can use dispatch_async(dispatch_get_main_queue(), ^{}). But if my window is modal, which just happens to be the case for the app I’m working on, then I use -performSelectorOnMainThread:withObject:waitUntilDone:.

2 Comments RSS · Twitter

On a similar note, have fun making a WebView that works inside a modal window. It'll never load its content because it's waiting on something to be dispatched in the main thread.

Regularly scheduled service announcement:

Instead of

[receiver performSelectorOnMainThread:@selector(done) withObject:nil waitUntilDone:NO];

use HOM:

[[receiver onMainThread] done];

Leave a Comment