I call dispatch_async(dispatch_get_main_queue(),block())
and my block()
fails to perform UI interactions, because it IS not getting called in main thread, why?
Note: I use PSPDFUIKitMainThreadGuard
I call dispatch_async(dispatch_get_main_queue(),block())
and my block()
fails to perform UI interactions, because it IS not getting called in main thread, why?
Note: I use PSPDFUIKitMainThreadGuard
You have to call UI modification blocks as dispatch_sync()
on the main thread, as this, it can refresh UI without being blocked.
Here is how you can do this in Swift:
runThisInMainThread { () -> Void in
// Run the method that crashes in here
}
func runThisInMainThread(block: dispatch_block_t) {
dispatch_async(dispatch_get_main_queue(), block)
}
Its included as a standard function in my repo, check it out: https://github.com/goktugyil/EZSwiftExtensions
You are not actually dispatching to the main thread, from the looks of your question, you are invoking your block and passing the return value of your block, e.g. dispatch_async(queue, yourReturnValue);
It should read:
dispatch_async(queue, yourBlock);
Not:
dispatch_async(queue, yourBlock());