检查当前线程是否是主线程 [英] Check whether or not the current thread is the main thread
本文介绍了检查当前线程是否是主线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有什么方法来检查当前线程是否是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屋!
查看全文