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!");
}
}
看看NSThreadAPI文档 https://developer.apple.com/documentation/foundation/nsthread?language=objc.
有类似的方法
- (BOOL)isMainThread
+ (BOOL)isMainThread
and + (NSThread *)mainThread
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)