Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are IBActions fired on main queue?

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?

like image 949
htzfun Avatar asked Jan 14 '15 14:01

htzfun


People also ask

Why does the main queue take so long to load?

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.

What happens when you remove the front element in a queue?

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.

How do I avoid blocking the current thread in a queue?

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.

What does the main dispatch queue do?

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.


1 Answers

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.

like image 165
Ricardo Avatar answered Sep 17 '22 02:09

Ricardo