Last Updated: February 25, 2016
·
1.328K
· _max_k

Code on the Main Thread?

Quick and easy to implement code to check to see if your code is running on the main thread or not, and if it isn't, in the case of UIKit events, switch to the main thread

BOOL isOnMainThread = [[NSThread currentThread] isEqual:[NSThread mainThread]];

if (!isOnMainThread)
{
    dispatch_async(dispatch_get_main_queue(), ^{

        [self callMethodAgainWithParams:aforelistedParams];

    });

    return;
}