iOS - Ensure execution on main thread

user236739 picture user236739 · Jul 20, 2012 · Viewed 113.7k times · Source

I want to know how to call my function on the main thread.

How do I make sure my function is called on the main thread?

(this follows a previous question of mine).

Answer

shoughton123 picture shoughton123 · Jul 20, 2012

This will do it:

[[NSOperationQueue mainQueue] addOperationWithBlock:^ {

   //Your code goes in here
   NSLog(@"Main Thread Code");

}];

Hope this helps!