Understanding method returning BOOL by using !=
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)shouldAutorotateToInterfaceOrientatio开发者_开发问答n:(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.
精彩评论