views:

41

answers:

1

Is there any way to specify if current thread is main thread or not in objective-c?

I want to do something like this.

  - (void)someMethod
  {
    if (IS_THIS_MAIN_THREAD?) {
      NSLog(@"ok. this is main thread.");
    } else {
      NSLog(@"don't call this method from other thread!");
    }
  }
+2  A: 

Have a look at NSTHread API documentation at this page. There are methods like - (BOOL)isMainThread + (BOOL)isMainThread and + (NSThread *)mainThread

rano
Thanks! That's what I want.
fish potato
^^ Specify this answer as the correct one so
rano