Goal C: Understanding Code

I have the following code:

- (IBAction)buttonSectionPressed:(id)sender { if ([self.switchReloadOnlyDontToggleVissibility isOn]) { [self updateCells:self.section2Cells]; } else { BOOL hide = ([sender tag] == 0); [self cells:self.section2Cells setHidden:hide]; } [self reloadDataAnimated:([self.switchAnimated isOn])]; } 

I have a question with

 BOOL hide = ([sender tag] == 0); 

Does it check if there is (sender.tag == 0), then assign it to hide? So (if sender.tag! = 0) does hide not exist?

+4
source share
1 answer

This expression works as follows:

  • Evaluates [sender tag]
  • Compares the result with zero
  • If the result is zero, hide set to YES ; otherwise, it is set to NO .

This can also be done with an equivalent expression that uses the property syntax:

 BOOL hide = (sender.tag == 0); 

Finally, you can completely remove the hide variable:

 [self cells:self.section2Cells setHidden:(sender.tag == 0)]; 
+8
source

All Articles