Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3347944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:28:57+00:00 2026-05-18T01:28:57+00:00

In the Cocoa and Cocoa Touch frameworks, enums are used as constant. I understand

  • 0

In the Cocoa and Cocoa Touch frameworks, enums are used as constant. I understand how to use it except in one case, the case you can pass as a parameter multiple value with the | operator. Like in :

pageControl.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin);

The enum is declared like that:

enum {
    UIViewAutoresizingNone                 = 0,
    UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
    UIViewAutoresizingFlexibleWidth        = 1 << 1,
    UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
    UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
    UIViewAutoresizingFlexibleHeight       = 1 << 4,
    UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
typedef NSUInteger UIViewAutoresizing;

How can I define myself this type of enum (i.e. what << means) and how can I check for multiples values when passed as a parameter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:28:57+00:00Added an answer on May 18, 2026 at 1:28 am

    << is the bitshift operator. So 1 << 2 tells it to shift the bit two spaces over.

    Example:

    In binary the number 1 is:

    0001
    

    1 << 2 means to shift all the bits to the left 2 spaces, which results in this value:

    0100
    

    or 4.

    So the values of each ENUM in your example is, 1, 2, 4, 8, 16, etc. They could have just as well set each enum to those values. But since they use that enum for multiple values, the binary values makes it more clear:

    0001
    0010
    0100
    1000
    

    so they wrote using the bit shifts.

    so if I OR (|) two of those values together, for example FlexibleLeftMargin (0001) and FlexibleWidth (0010), I would get the following value:

    0011
    

    So they use each bit as a flag so they know you have multiple values set.

    You can now use the AND operator & to figure out if you have a specific value set.

    0010 & 0011 = 0010
    

    So you could do this to check if you have one of enums set:

    myenum = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin);
    if((myenum & UIViewAutoresizingFlexibleLeftMargin) == UIViewAutoresizingFlexibleLeftMargin) {
      // myenum has UIViewAutoresizingFlexibleLeftMargin set!
    }
    

    Hopefully this makes sense.
    For a more thurough explanation on bitwise operations read this: Wikipedia ~ Bit Operators or search around for “bit operators“

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use a C++ library (CLucene) from my Cocoa Touch iPhone application
In cocoa-touch development... Use AppDelegate for delegate classes Create separate delegate class and locate
I have created a cocoa touch static that uses standard apple frameworks like MediaPlayer.framework
I have two cocoa-touch apps in one Xcode project. Xcode gives me iPhone/iPad related
In Xcode, you can view all the header files of the cocoa-touch framework, but
Is it possible to create an own obj-C Cocoa Touch framework which can be
I have made simple cocoa touch apps before but I have never used UINavigationControllers,
In iOS and Cocoa Touch, sometimes it seems we can get by without calling
I'm in urgent need of an Objective-C/Cocoa/Cocoa Touch framework to handle simple charting; pie
In Cocoa/Touch, CAMediaTimingFunction represents four control points that specify a cubic bezier curve of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.