0

What does the (void)sender; do in following code? I am not able to understand what the use of that expression is.

- (IBAction)signIn:(id)sender {
       (void)sender;    
       [self dismissKeyboardIfNeeded];
}
jscs
  • 63,694
  • 13
  • 151
  • 195
AAV
  • 3,785
  • 8
  • 32
  • 59

1 Answers1

5

It's one way of letting the compiler know that the sender parameter is not used in the method.

mipadi
  • 398,885
  • 90
  • 523
  • 479
  • IS there any particular reason why we need to tell compiler ? – AAV May 20 '13 at 17:58
  • 1
    You can enable warnings about unused function and method parameters; in some cases, you may not be able to change the method signature and so don't want to be warned about unused parameters. – mipadi May 20 '13 at 18:00
  • I've never seen such a warning. It's not normally enabled, AFAIK, even though unused local declares are flagged. – Hot Licks May 20 '13 at 18:14
  • @HotLicks: Check out the gcc warning options, which are also supported by clang, I believe: http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html – mipadi May 20 '13 at 18:17
  • why send in a parameter, that is not going to be used? – lakshmen May 20 '13 at 18:27
  • 1
    @lakesh: Callbacks often taken a pre-determined set of parameters. For example, in Cocoa, UI actions take a `sender` parameter, but you might not actually use the `sender` parameter in your code. – mipadi May 20 '13 at 18:30