相关疑难解决方法(0)

检查当前线程是否是主线程

有没有办法检查当前线程是否是Objective-C中的主线程?

我想做这样的事情.

  - (void)someMethod
  {
    if (IS_THIS_MAIN_THREAD?) {
      NSLog(@"ok. this is main thread.");
    } else {
      NSLog(@"don't call this method from other thread!");
    }
  }
Run Code Online (Sandbox Code Playgroud)

iphone cocoa multithreading objective-c xamarin.ios

117
推荐指数
5
解决办法
4万
查看次数

标签 统计

cocoa ×1

iphone ×1

multithreading ×1

objective-c ×1

xamarin.ios ×1