NSTimerとNSThreadの違い
[[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(aMethod:) userInfo:aInfo repeats:NO] fire]
ってやった時に呼ばれるaMethodの引数はNSTimerのインスタンスだが
[NSThread detachNewThreadSelector:@selector(aMethod:) toTarget:self withObject:aInfo];
ってやった時のaMethodの引数はaInfo自体。
なのでNSTimerの時には例えばaInfoがNSDictionaryなら
NSDictionary* info = [timer userInfo];
とかやる。
あとNSTimerはあくまでメインスレッドの中で「あとでイベントを発生させる」ってスケジュールを入れるものだけど、NSThreadはスレッドが分かれるのでaMethodの冒頭でautoreleasepoolを別途作ってやる必要が出て来る。
例えば
NSLog(@"enter aMethod");
NSAutoreleasePool pool = [[NSAutoreleasePool alloc] init];
という間違いをすると
2009-10-13 17:57:32.845 Camera[4465:4717] enter aMethod
2009-10-13 17:57:32.850 Camera[4465:4717] *** _NSAutoreleaseNoPool(): Object 0x3d79530 of class NSCFString autoreleased with no pool in place - just leaking
という怒られ方をする。スレッドを作ったのにAutoreleasePoolが作られていないので「プールがないのにNSCFStringをオートリリースしようとした!」って言ってるわけだな。