プロが教えるわが家の防犯対策術!

Objective-C,NSTimerを使って1秒毎に10秒かかる処理を実行させる事ってできますか?

例えば、以下に書いたとすると、(行頭全角スペースです。)
@interface testTimer : NSObject {
 NSTimer *timer;
}
@end

@implementation testTimer
- (id) init {
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
 target: self
 selector:@selector(timeUpdate:)
 userInfo:nil
 repeats:YES];
}

- (void) timeUpdate:(id)sender {
 NSLog(@"%@",[NSDate date]);
  [NSThread sleepUntilDate:[[NSDate date] addTimeInterval:10.0]];
}
@end

毎秒タイムスタンプは出力されませんでした。

以上、ご指導の程、よろしくお願いいたします。

A 回答 (1件)

NSOperationやGrand Central Dispatchなどを使って、マルチスレッドで処理すればよいのでは。

    • good
    • 0
この回答へのお礼

osamuyさん、ご回答ありがとうございました。

教えて頂いたキーワードでぐぐったら、それらしいサンプルを見つける事ができました。

お礼日時:2010/05/09 23:17

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!