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 aBOOLvalue. If the comparison is true, the expression(....)takes the valueYES(which is the same asTRUE).It isn’t an implicit conversion, it is just how comparisons work.