Skip to content

Instantly share code, notes, and snippets.

@katsuhide
Last active December 17, 2015 22:59
Show Gist options
  • Save katsuhide/5685828 to your computer and use it in GitHub Desktop.
Save katsuhide/5685828 to your computer and use it in GitHub Desktop.
タイマー周りの処理
/*
* main
*/
- (void)run{
// タイマーで使うデータ
NSNumber *number = [[NSNumber alloc] initWithInt:1];
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:number forKey:@"count"];
// タイマーを作成
NSTimer *timer = [NSTimer
scheduledTimerWithTimeInterval:3.f
target:self
selector:@selector(polling:)
userInfo:dic
repeats:YES];
// stop
[timer invalidate];
// stat
[timer fire];
// status
[timer isValid];
}
/*
* Polling処理
*/
- (void)polling: (NSTimer*)timer{
NSNumber *number = [[timer userInfo] objectForKey:@"count"];
NSLog(@"count up:%@", number);
int sum = [number intValue];
sum = sum + 1;
[[timer userInfo] setObject:[[NSNumber alloc]initWithInt:sum] forKey:@"count"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment