isMainThread
現在のスレッドがメインスレッドかを返します
解説
現在のスレッドがメインスレッドかを返します。
返り値
( BOOL )
メインスレッドかYES/NO
引数
フレームワーク
Foundation
クラス
NSThread
Class Methods
使用可能
10.5
参照
+ mainThread
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { [NSThread detachNewThreadSelector:@selector(threadTask:) toTarget:self withObject: barA ]; [NSThread detachNewThreadSelector:@selector(threadTask:) toTarget:self withObject: barB ]; NSLog(@"%@------- ",(([[NSThread currentThread] isMainThread])?@"main":@"sub")); if ([NSThread isMultiThreaded]){ NSLog(@"YES"); }else{ NSLog(@"NO"); } } - (void)threadTask:(id)obj { int i; NSAutoreleasePool *pool = [NSAutoreleasePool new]; for (i=1;i<20000;i++) { NSLog(@"%@------- %d",(([[NSThread currentThread] isMainThread])?@"main":@"sub"),i); [obj setDoubleValue:(double)i]; } [pool release]; [NSThread exit]; } @end