Reputation: 1915
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)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?
Upvotes: 1
Views: 174
Reputation: 1
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.
Upvotes: 0
Reputation: 58
Perhaps it means something different in Objective C, but in C, C++, and Java the || operator is logical OR.
Upvotes: 0
Reputation: 22633
In most programming languages (notable exceptions: Python, Ruby, etc.) || is the logical "OR" operator.
See also == (equals), != (does not equal), and && (and).
Upvotes: 0
Reputation: 15570
the function wil return a Boolean true if toInterfaceOrientation == UIInterfaceOrientationPortrait
OR UIInterfaceOrientationIsLandscape()
returns true.
Upvotes: 0
Reputation: 269408
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.
Upvotes: 1
Reputation: 170839
|| 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.
Upvotes: 1