I have found the oddest behavior with my iOS app. I have this code:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
CMLog(@"Start Save RoundQuestions Asynchronously");
[round saveRoundQuestions:target selector:selector];
});
That function finishes it’s work and calls this:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[target performSelector:selector];
#pragma clang diagnostic pop
The logs show everything running properly, however the target calls a pushViewController on a navigationController, and it takes forever to do the actual push. I can force it to go on by clicking the home button. I’ve read that I’m probably violating thread safety and the run loop may need to be awakened.
Is it wrong to call a selector from a dispatch_async? Or do I need to perform the selector on the main thread where the UI is?
EDIT: I actually figured out the problem. It turns out that I was calling a function that was blocking the UI inside of the saveRoundQuestions which I believe was forcing the push animations to the back of the line, so to speak. I put this function in the background and the push animation now happens immediately. But I’m still curious as to why?
You can successfully update UI using dispatch_async. Just instead of using
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)usedispatch get_main_queue()edit:
According to your update. If you are doing some expensive job inside
saveRoundQuestions, and then updateUI, you should use:And then inside of
saveRoundQuestionsput another block indispatch_get_main_queue()to update UI.