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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:46:45+00:00 2026-05-28T03:46:45+00:00

What is the difference between declaring variables in the interface section vs. in the

  • 0

What is the difference between declaring variables in the interface section vs. in the implementation section outside of a method.

  • 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-28T03:46:45+00:00Added an answer on May 28, 2026 at 3:46 am

    Do you mean in the ivar block in the implementation, as in

    @implementation MyClass {
        id someIvar;
    }
    // methods go here
    @end
    

    If so, then the only difference is visibility to other code. At runtime, the ivar will be indistinguishable from one declared in the @interface section. However, code outside the class can see ivars declared in @interfaces, and unless those ivars are marked with @protected or @private, then the other classes can reach in and twiddle the ivars. But ivars declared in the @implementation are not even visible to code outside, so they cannot touch the ivars.

    For the most part, this is just a code cleanliness issue. Nothing should go in the header file unless it’s meant to be public. So why put ivars there?

    As Josh Caswell noted, ivars declared in this fashion require a recent version of Clang.


    The alternative interpretation of your question is you have code like

    @implementation MyClass
    
    - (void)someMethod { /* ... */ }
    
    NSString *var;
    
    - (void)otherMethod { /* ... */ }
    @end
    

    If this is what you meant, then the answer is, don’t do that. In this code snippet we’ve declared a global variable named var rather than an instance variable. The location of the variable inside the @implementation block is irrelevant, it’s exactly identical to a global variable in C (because that’s what it is).

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

Sidebar

Related Questions

When declaring variables in an interface what is the difference between the two: @interface
Possible Duplicate: Difference between declaring variables before or in loop? Consider the two codes
Recently I've been thinking about performance difference between class field members and method variables.
Is there a difference between declaring a static variable outside of a function and
Could someone please explain what's the difference between inheriting from ISerializable interface and declaring
Possible Duplicate: Difference between declaring variables before or in loop? Is there any (or
Is there any difference between using the @PostConstruct annotation and declaring the same method
According to the standard, what is the difference in behavior between declaring variables in
In Objective-C, what's the difference between declaring a variable id versus declaring it NSObject
Duplicate Whats the difference between declaring as new and as something new something 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.