有没有办法判断当前线程是否是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!");
}
}
有没有办法判断当前线程是否是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