I tried to search this out, but kinda stuck in this question. All guides about UI say, that all UI stuff should be on GCD main thread, but no one says about inner implementation of IBActions.
So, are IBActions fired on GCD main thread or not?
The reason for this is that the main queue is responsible for everything UI related, but like we already established, the main queue is a serial queue. So if the main queue is busy doing something, it can't respond to user input or draw new frames of your animation. A lot of code in iOS is code that can take a while to run.
Naturally, the element inserted first will be at the front of the queue so we will remove the front element and let the element behind it be the new front element. This is similar to the peek operation in stacks, it returns the value of the element at the front without removing it.
Remember to always dispatch your queue to the main queue asynchronously using DispatchQueue.main.async to avoid blocking the current thread. And potentially even deadlocking your app, which can happen if you call DispatchQueue.main.sync from code that is already on the main queue.
The main dispatch queue is a queue that runs one task at a time. It's also the queue that performs all layout updates. If somebody talks about the importance of not blocking the main thread, what they're really saying is that they don't want to keep the main dispatch queue busy for too long.
Yes, and you can test it by yourself using NSLog(@"is main thread? %d", [NSThread isMainThread]);
You can also use the debugger and left view to know about what thread is been executed your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With