Skip to content

Instantly share code, notes, and snippets.

@bryanluby
Created September 18, 2013 21:01
Show Gist options
  • Save bryanluby/6615647 to your computer and use it in GitHub Desktop.
Save bryanluby/6615647 to your computer and use it in GitHub Desktop.
Objc: Switch with ternary operator
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