Reputation: 1448
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?
Upvotes: 12
Views: 1629
Reputation: 14033
It is safe to assume that @IBAction
s are only called on the main thread by Apple's code under the hood. Apple's documentation:
Important: Use UIKit classes only from your app’s main thread or main dispatch queue, unless otherwise indicated. This restriction particularly applies to classes derived from UIResponder or that involve manipulating your app’s user interface in any way.
Note: it is entirely possible for your code to call an @IBAction
's method on a background thread. That is why I make that distinction.
Note: If you are here because an error on an IBOutlet, Make your IBOutlets strong (not weak) to avoid accessing dereferenced IBOutlets in some cases.
Upvotes: 3
Reputation: 2943
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.
Upvotes: 6