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 7966545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:27:34+00:00 2026-06-04T06:27:34+00:00

I need to create an instance variable of type BOOL with a default value

  • 0

I need to create an instance variable of type BOOL with a default value of False in one of my Objective-C classes. How do I do this? I’ve seen people define it in their .h file but I don’t really need this variable to be public. Thus shouldn’t I put it in my .m file? Additionally, should I make it a property? Or should I ever not make something a property? Thanks.

  • 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-06-04T06:27:36+00:00Added an answer on June 4, 2026 at 6:27 am

    I need to create an instance variable of type BOOL with a default value of FALSE in one of my objective c classes. How do I do this?

    Assuming you are using the current Xcode, you can declare the ivar in the implementation like this:

    @implementation MyClass
    {
    @private
        BOOL myBool;
    }
    

    I’ve seen people define it in their .h file but I don’t really need this variable to be public.

    Historically, you had to declare instance variables in the @interface because of the way classes were implemented. This is now necessary only if you are targeting 32 bit OS X.

    Additionally, should I make it a property?

    That depends. You should definitely make it a property if it is part of your class’s external API (for unrelated classes or subclasses to use. If it’s only part of the object’s internal state, you don’t need to make it a property (and I don’t).

    Or should I ever not make something a property? Thanks.

    If you are not using ARC and the type is an object type (BOOL is not) you should always make it a property to take advantage of the memory management of the synthesized accessors. If you are using ARC, the advice on the Apple developer list is to make stuff that is part of the API properties and stuff that is internal state as ivars.

    Note that, even for internal state, you might want to use KVO, in which case, use a property.

    If you declare this BOOL as a property and synthesize it, you do not need to explicitly declare the ivar. If you want to make the property “visible” only to the class itself, use a class extension

    @interface MyClass()
    
    @property (assign) BOOL myBool;
    
    @end
    
    @implementation MyClass
    
    @synthesize myBool = myBool_;  // creates an ivar myBool_ to back the property myBool.
    
    @end
    

    Note that, although the compiler will produce warnings for the above, at run time, any class can send setMyBool: or myBool to objects of MyClass.

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

Sidebar

Related Questions

I need this roadmap of a Hibernate managed object instance. First, I create an
I have a lot action methods which do not need to create instance variable
Why do i need to create an instance of Random class, if i want
i need create a variable with parent subclass. Example: Parent Class <?php class parentClass
I have created a instance variable in rails project, which gets its value from
We need to create & destroy instances of QApplication, as we want to use
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution
I need create clone repository. but I do not know where can I get
I need create a document word with Java. And I ask, how can I

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.