Skip to content

Instantly share code, notes, and snippets.

@Morse-Code
Created April 6, 2013 20:38
Show Gist options
  • Save Morse-Code/5327535 to your computer and use it in GitHub Desktop.
Save Morse-Code/5327535 to your computer and use it in GitHub Desktop.
Objective-C Ternary Trick One unique ability of using the ternary operand with objects is that the code can be shorted even further – if the value being checked is also the value after the ternary operator, the value can be omitted from the operation:
- (void)displayErrorMessage:(NSString *)msg
{
// Even shorter version, when the operand is also the "True" case:
NSString *msgFullString = [NSString stringWithFormat:@"Message: %@", msg ? : @"Unknown error"];
NSLog(@"%@", msgFullString);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment