What does '||' mean in objective C?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfa开发者_高级运维ceOrientation)toInterfaceOrientation {
// Return YES if incoming orientation is Portrait
// or either of the Landscapes, otherwise, return NO
return (toInterfaceOrientation == UIInterfaceOrientationPortrait) || UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
What does the '||' mean here?
Same thing as the C ||
operator: logical or.
|| is a logic 'or' operation - it returns true if at least one of its operands is true.
Moreover, if its first operand evaluates to true it returns true without evaluating its second operand.
It's a short-circuiting logical OR.
It returns true if either toInterfaceOrientation == UIInterfaceOrientationPortrait
or UIInterfaceOrientationIsLandscape(toInterfaceOrientation)
, but the second operand is only evaluated if/when the first operand is false.
It means OR. Just the way Obj-C uses it.
|| = OR && = AND
the function wil return a Boolean true if toInterfaceOrientation == UIInterfaceOrientationPortrait
OR UIInterfaceOrientationIsLandscape()
returns true.
In most programming languages (notable exceptions: Python, Ruby, etc.) || is the logical "OR" operator.
See also == (equals), != (does not equal), and && (and).
Perhaps it means something different in Objective C, but in C, C++, and Java the || operator is logical OR.
Logical operator OR
. See here
If UIInterfaceOrientationPortrait is equal to toInterfaceOrientation then it will return true, otherwise it will return the value of UIInterfaceOrientationIsLandscape(toInterfaceOrientation), which may be true or false.
精彩评论