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

  • SEARCH
  • Home
  • 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 4252108
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:45:04+00:00 2026-05-21T04:45:04+00:00

Sometimes my interfaces end up having a lot of flag variables, such as isThatFeatureEnabled

  • 0

Sometimes my interfaces end up having a lot of flag variables, such as isThatFeatureEnabled. Or, even worse, I will have an interface containing only flags and instance information.

While reading some UIKit header files, I found out that some classes declare a structcontaining all the internal flags they need. For example UIView has this:

struct {
    unsigned int userInteractionDisabled:1;
    unsigned int implementsDrawRect:1;
    unsigned int implementsDidScroll:1;
    unsigned int implementsMouseTracking:1;
    unsigned int hasBackgroundColor:1;
    unsigned int isOpaque:1;

    // ...

} _viewFlags;

How does this work and how is it used?

Also, (sorry if this may seem unrelated), take StoreKit’s SKProduct, for example. It doesn’t have any methods, just readonly properties for getting instance specific information, such as localizedDescription, localizedTitle and price. But how is it initialized? How does the code that initializes instances of this class set those properties in the first place if they’re readonly? I see this class also has an id _internal ivar; what’s that for?

Often I end up with interfaces similar to SKProduct, except that my properties can’t be readonly, because I have no idea how to set them when I need to initialize an instance, for example in an XML parsing code.

  • 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-21T04:45:05+00:00Added an answer on May 21, 2026 at 4:45 am

    The structure that you have presented is the way that C, C++ and Objective C have for declaring bitfields. It has an advantage over something like #define MYFLAG 0x0001 in that you get compiler checking, so that you don’t do any of the following:

    • Accidentally assign the same bit to more than one flags
    • Accidentally overwrite a flag with a number (e.g. flag=34)
    • Accidentally use one #define with the wrong variable (e.g. myColor=FLAG_TEMPERATURE_HIGH).

    You can set all of the variables at the same time doing a structure assignment in C++. You couldn’t do that in C or Objective-C the last time I looked, but you may be able to do so now.

    You set and get these flags like any other instance variable.

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

Sidebar

Related Questions

I have 2 classes both inherit from the same interface. i want sometimes to
I have somewhat of a problem. We have a centralized interface engine that will
Sometimes I have to implement an interface or inherit a virtual (MustInherit) that the
Sometimes framework objects put helper class interfaces inside of *.m files, such as: Foo.m:
I have two simple interfaces: public interface HasId<ID extends Serializable> extends Serializable { T
When I use Jasper as an interface, sometimes the interface invoke jasper and generate
Memcached interface is implemented using a textual protocol. Sometimes it's very useful to be
Sometimes IE6 will render the text of a <ul> list the same color as
Sometimes I have to work on code that moves the computer clock forward. In
Sometimes a labeled break or continue can make code a lot more readable. OUTERLOOP:

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.