Last active
December 17, 2015 22:59
-
-
Save katsuhide/5685828 to your computer and use it in GitHub Desktop.
タイマー周りの処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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