これを行う方法が少しわかりません:
アプリの「寿命」の間実行される「ワーカースレッド」を開始します。
[NSThread detachNewThreadSelector:@selector(updateModel) toTarget:self withObject:nil];
それから
- (void) updateModel {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
BackgroundUpdate *update = [[BackgroundUpdate alloc] initWithTimerInterval:5];
[[NSRunLoop currentRunLoop] run]; //keeps it going 'forever'
[update release];
[pool release];
}
これで、スレッドは 5 秒 (initWithTimerInterval) ごとに「ウェイクアップ」して、実行できるタスクがあるかどうかを確認します。BackGroundUpdate クラスのすべてのタスクは、現時点では時間依存のみです。「イベント依存」のものをいくつか用意したいと思います。たとえば、バックグラウンド オブジェクトをメイン スレッドから呼び出して、「speedUp」、「slowDown」、「reset」、またはオブジェクトの任意のメソッドに指示したいとします。
これを行うには、次のようなものが必要だと思いperformSelectorOnThread
ますが、NSthread と Background オブジェクトへの参照を取得するにはどうすればよいですか?