Send IBAction sender as id or specific class

I see two approaches to handling sender objects in IBAction statements. The first is as follows:

-(IBAction)buttonPressed:(id)sender{
 UIButton*someButton=(UIButton*)sender;
 //do something with someButton.tag or whatever
 }

To others it seems easier:

 -(IBAction)buttonPressed:(UIButton*)sender{
  //do something with sender.tag or whatever
  }

I generally choose version 2. Any special reasons prefer one style over another, if you know that only this button will send this method?

I see where version 1 is good if something can be the sender, for example, a button or switch or slider, etc. But if you are looking for properties UIButtonsuch as tag, this will not make much difference if your sender is not UIButton. So version 2 seems a lot simpler.

Just thought that I would see if I have an obvious reason to prefer version 1.

+5
1

. , , . , , , , .

, :

- (IBAction)buttonPressed {
  // Do something.
} 
+4

All Articles