Fallthrough in switch statement for iOS/Objective-C

ios, objective-c, switch-statement

Solution

Yes, it's fine to do that.

I've used it before. It stops duplicate code.

Problem

Say I have a switch statement with five cases, but only two real methods ever being called, like so: ``` switch (condition) { case conditionOutcome1: [self firstMethod]; break; case conditionOutcome2: [self secondMethod]; break; case conditionOutcome3: [self firstMethod]; break; case conditionOutcome4: [self firstMethod]; break; case conditionOutcome5: [self secondMethod]; break; default: break; } ``` Is it safe to group up the cases, like so? ``` switch (condition) { case conditionOutcome1: case conditionOutcome3: case conditionOutcome4: [self firstMethod]; break; case conditionOutcome2: case conditionOutcome5: [self secondMethod]; break; default: break; } ``` It works fine, but I've never used it before in objective-c so I'd like to make sure I'm not causing any problems by saving a few lines of code. Thanks!

Original source