How do I pass an argument to @selector()?

2 Solutions Collect From Internet About “How do I pass an argument to @selector()?”

In this instance, you don’t. Check the reference docs:

The message to send to target when the timer fires. The
selector must have the following

  • (void)timerFireMethod:(NSTimer*)theTimer

The timer passes itself as the
argument to this method.

So the only parameter your panelVisibility: method can accept is an NSTimer*, and the timer will pass this in automatically for you.

What you can do, however, is use the userInfo field to pass whatever other information you want. So you could, for instance, do:

[NSTimer scheduledTimerWithTimeInterval:2.0
                               userInfo:[NSNumber numberWithBool: myBool]

…and then have:

    BOOL visible = [theTimer.userInfo boolValue];

You can’t do that. Note that the docs says the method must have the following signature:

- (void)timerFireMethod:(NSTimer*)theTimer

Use the userInfo parameter to pass an [NSNumber nnumberWithBool:bool] and retrieve it by calling:

BOOL isSomething = [[theTimer userInfo] boolValue];

Inside the method the timer called when fired.