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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:30:01+00:00 2026-06-06T00:30:01+00:00

Why must I define variables twice in the header file? What differences are there

  • 0

Why must I define variables twice in the header file? What differences are there between these variables?

The first definition is here:

@interface MyController: UIViewController
{
    NSInteger selectedIndex;
}

The second definition is here:

@property (nonatomic) NSInteger selectedIndex;
  • 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-06T00:30:03+00:00Added an answer on June 6, 2026 at 12:30 am

    What you’re seeing was required in earlier versions of Objective-C,
    but isn’t any more.

    In the first versions of Objective-C used by NeXT up until the new
    runtime was introduced (with Objective-C 2.0 on Mac OS X), all
    instance variables had to be declared as part of the class’s structure
    in its @interface. The reason was that if you subclassed a class,
    the compiler needed to know the instance variable layout of the class
    so it could see at what offset to put the subclass’s instance
    variables.

    When properties were introduced, synthesized properties had to be
    “backed” by an instance variable in the class’s structure. Therefore
    you had to declare both an instance variable and the property.

    All of the above is no longer true. Newer Objective-C is less fragile
    in the way it looks up instance variable offsets, which has meant a
    few changes:

    • not all instance variables need to be in the @interface. They can now be defined in the @implementation: though not in categories due
      to the possibilities of clashing and other issues.
    • instance variables for synthesized properties can be inferred and created based on the property definition.
    • you can programmatically add instance variables to classes you’re creating at runtime (only before you’ve registered the class as
      available to the system).

    So, to reiterate, you only needed to declare both the instance
    variable and a synthesized property in older versions of the
    Objective-C language. What you’re seeing is redundant and should not
    be considered a “best practice”.

    [Source]

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

Sidebar

Related Questions

I'm trying to define variables within a loop. I'll drop the code here and
I've heard there are differences between languages about the meaning of the keyword static
Given that users must be able to define their own fields on an object,
Say I want to define that an URI such as: myapp://path/to/what/i/want?d=This%20is%20a%20test must be handled
it must be jquery I have file text.html with 6 div in (a,b,c,d,e,f) In
According to this question's answer : According to the standards you must define i
Could someone please explain what is meant by the following ? You must define
I have a string that stores some variables that must be executed to produce
In C, unlike C++, all parameters to a function definition must be named. Instead
I am programming a c project which must use the pow function defined in

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.