Take the 2-minute tour ×

when I call the method

- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view 

of UIPopoverController, I pass UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown as arguments for the permittedArrowDirections parameter.

my question is simple :

How can I test the presence of UIPopoverArrowDirectionDown in arrowDirections ?

if (arrowDirections == UIPopoverArrowDirectionDown)
    NSLog(@"arrowDirections contains UIPopoverArrowDirectionDown");

doesn't work.

share|improve this question
why would you test this? what is possibleDirections? –  jaydee3 Jun 8 '12 at 8:54
I'm building a custom view and I reuse UIPopoverArrowDirection so I need to test which directions are permitted. possibleDirections is arrowDirections in my example sorry. I'm gonna rename it –  Dabrut Jun 8 '12 at 9:00
add comment

1 Answer

up vote 0 down vote accepted
if (arrowDirections & UIPopoverArrowDirectionDown == UIPopoverArrowDirectionDown) {
    NSLog(@"arrowDirections contains UIPopoverArrowDirectionDown");
share|improve this answer
It works. Can you explain the meaning of the "&" in this context please ? –  Dabrut Jun 8 '12 at 9:06
see somacon.com/p125.php –  jaydee3 Jun 8 '12 at 9:11
& is the binary AND operator. By ANDing the two values, you basically extract the bits of UIPopoverArrowDirectionDown from all the bits set in arrowDirections. The resulting value is equal to UIPopoverArrowDirectionDown if its bit are set in arrowDirections and otherwise not. It's sort of the inverse of using the binary OR (|) that you use to add a new value to a bit field. –  Ole Begemann Jun 8 '12 at 9:11
Because arrowDirections works like a bit field. You wrote yourself that you are assigning UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown to the variable. Clearly, UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown != UIPopoverArrowDirectionDown. –  Ole Begemann Jun 8 '12 at 10:21
(arrowDirections & UIPopoverArrowDirectionDown) != 0 is probably more standard way to say the same, without repeating the constant –  Sulthan Jun 8 '12 at 10:29
show 2 more comments

Your Answer


