Is it possible to initiate a timer and pass the selector method with multiple arguments?
Below is a simple example of a working timer:
gameTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(gameLoop:)
userInfo:nil
repeats:YES];
The selector method would be named - (void)gameLoop:(NSTimer *)theTimer;
Is it possible to pass this selector method with multiple arguments? So that the gameLoop method could also deal with an int value and a bool value?
The following obviously doesn’t work, but might highlight what I’m after:
gameTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(gameLoop:NO:75)
userInfo:nil
repeats:YES];
- (void)gameLoop:(NSTimer *)theTimer isRunning:(bool)running numberOfSteps:(int)steps;
I disagree with BOTH answers. Of course you can pass whatever info you want to the method your NSTimer calls. That’s what the
parameter is for!
Now you can extract the userInfo in the selector.