// in your pch file...
#define statusString (statusBool ? @"Approved" : @"Rejected")
// in your m file...
[NSString stringWithFormat: @"Status: %@", statusString]
三元运算符示例。如果值为isFemale
布尔变量是YES,打印“性别是女性”,否则打印“性别是”
男" < / p >
? means = execute the codes before the : if the condition is true.
: means = execute the codes after the : if the condition is false.
objective - c
BOOL isFemale = YES;
NSString *valueToPrint = (isFemale == YES) ? @"GENDER IS FEMALE" : @"GENDER IS MALE";
NSLog(valueToPrint); //Result will be "GENDER IS FEMALE" because the value of isFemale was set to YES.
为迅速
let isFemale = false
let valueToPrint:String = (isFemale == true) ? "GENDER IS FEMALE" : "GENDER IS MALE"
print(valueToPrint) //Result will be "GENDER IS MALE" because the isFemale value was set to false.