Created
April 6, 2013 20:41
-
-
Save Morse-Code/5327549 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:
This file contains hidden or 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)displayErrorMessage:(NSString *)msg | |
{ | |
// Even shorter version, when the operant is the same as 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