检查当前线程是否为主线程 [英] Check whether or not the current thread is the main thread

查看:39
本文介绍了检查当前线程是否为主线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以检查当前线程是否是Objective-C中的主线程?

Is there any way to check whether or not the current thread is the main thread in 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!");
    }
  }

推荐答案

看看 NSThread API 文档.

Have a look at the NSThread API documentation.

有像

- (BOOL)isMainThread

+ (BOOL)isMainThread

+ (NSThread *)mainThread

这篇关于检查当前线程是否为主线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆