Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

basic syntax question

ryantcbryantcb Posts: 666Registered Users @ @ @
Searching SO for how to determine the status of push notifications in my app, I came across what I'm sure is basic syntax but I have not used nor seen before. Its an if statement. The user answer says, instead of:
if (types == UIRemoteNotificationTypeNone)
you can use
if (types & UIRemoteNotificationTypeAlert)

I have not seen the single '&' used before. Is it really just the same as '==' . Or is the single '&' only usable is certain conditions such as you would use 'isEqualTo..' instead of '==' when checking strings?

if so what are those conditions?

Replies

  • givensurgivensur On the Information SuperhighwayPosts: 541Registered Users @ @ @
    edited January 2014
    No, it's not the same as ==. It is the bitwise AND operator.

    Here's the wikipedia page on bitwise operators in C.

    Per the documentation, UIRemoteNotificationTypeAlert is set as 1 << 2, which is 100 in binary.

    The statement "if (types & UIRemoteNotificationTypeAlert)", is checking to see that types has a 1 in the same spot. If you used ==, then only 100 would pass the test, whereas using & 100, 101, 110, and 111 all pass the test, which is what would most likely be wanted.
    I make cake apps.
  • ryantcbryantcb Posts: 666Registered Users @ @ @
    Excellent answer thank you
Sign In or Register to comment.