This is a rather basic question regarding the syntax of the return statement in the shouldAutoRotateToInterfaceOrientation
method of a view controller.
In order to allow all views except for the upside-down portrait mode, I have the following chunk of code implemented:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
What exactly is the return statement doing? I understand that it is returning a boolean variable, but how is it determining whether to return true or false? Is this a kind of implicit if statement inside of the return statement? I.e. would:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown)
return YES;
}
technically be the same thing, just more explicitly stated?
Thanks for the clarification!
The result of a comparison like (something != something_else)
is a BOOL
value. If the comparison is true, the expression (....)
takes the value YES
(which is the same as TRUE
).
It isn't an implicit conversion, it is just how comparisons work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With