Created
September 18, 2013 21:01
-
-
Save bryanluby/6615647 to your computer and use it in GitHub Desktop.
Objc: Switch with ternary operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ConditionalSwitchUsingNumber(int number); | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool | |
{ | |
ConditionalSwitchUsingNumber(0); | |
ConditionalSwitchUsingNumber(1); | |
ConditionalSwitchUsingNumber(2); | |
ConditionalSwitchUsingNumber(6); | |
} | |
return 0; | |
} | |
void ConditionalSwitchUsingNumber(int number) | |
{ | |
NSString *condString = | |
(number == 0) ? @"foo" : | |
(number == 1) ? @"bar" : | |
(number == 2) ? @"baz" : | |
@"foo"; | |
NSLog(@"String: %@", condString); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment