在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 documentation .
有类似的方法
- (BOOL)isMainThread
+ (BOOL)isMainThread
和+ (NSThread *)mainThread
https://stackoverflow.com/questions/3546539/
相关文章:
objective-c - 允许与另一个 UIView 下的 UIView 交互
iphone - 如何使 UIView 的 subview 居中
objective-c - "Auto Layout still required after ex
ios - 如何自定义分组表格 View 单元格的背景/边框颜色?
iphone - cocoa 应用程序的 info plist 中的 "bundle display
objective-c - NSLog 覆盖描述方法中对象的内存地址
objective-c - 在什么情况下,我们需要在 ARC 下编写 __autoreleasing