In JavaScript, the || operator will return the first non-false-evaluating operand. For example:
var x = null;
var y = "yup";
var z = x || y; // z is now "yup"
Is there an Objective-C equivalent for this?
For example:
NSString *x = nil;
NSString *y = @"yup";
NSString *z = x ... y; // z should now be @"yup", if "..." were an operator
Please Note: The '||' does short-circuit in JavaScript
There's a compiler extension to C (and therefore ObjC) that does what you want:
z = x ?: y;
(for a standard C/ObjC version: z = x ? x : y)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.