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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:51:35+00:00 2026-05-11T20:51:35+00:00

there is something I try to understand. I have this object declaration in my

  • 0

there is something I try to understand. I have this object declaration in my AppsController-Class for a Cocoa Application

NSMutableArray *personArray;

In can put this declaration inside the Header file or inside the implementation of the class in the code file. It makes no difference. I can even put it outside the @implementation context right under the #import commands.The Application works just fine.

Since I don’t inherit from the AppsController Class or do anything else fancy with it I wonder what might be the difference between these types of declarations?

Where does the declaration really belong?

  • 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-11T20:51:35+00:00Added an answer on May 11, 2026 at 8:51 pm

    It depends on how you want to use the variable. If you place the variable declaration inside the interface for your class, each instance of your class will have its own copy of the variable, which is kept separate from all other instances of your class:

    @interface AppsController : NSObject
    {
        NSMutableArray *personArray;
    }
    

    Each instance of the AppsController class will have its own copy of the personArray variable, which is separate from all other instances of the class.

    If, however, you define the variable outside of the interface, it becomes a global variable, and it is a shared (instances of your class do not get their own copy), and can be accessed from any instance of your class. If you declare it in the header as such:

    NSMutableArray *personArray;
    

    it is also visible to methods in other files and classes that include your header.

    If you declare the variable in the implementation file, but outside of the implementation itself, and prefix it with the static keyword, the variable will only be visible to the implementation of your class. This is common when you want a variable that is visible to you all of class instances, but not visible to anyone else, and is a way to create class variables.

    Since your object is a controller object, I am guessing that you only have one instance of it present in your application. You should declare the variable either:

    1. As an instance variable if your personArray variable needs to be unique to each instance of your controller class (even if you only have one instance now, you may have more than one instance of it in future).
    2. As a class variable (using the static keyword) if you want the variable to be visible to all instances of your class, with only one, shared instance of the variable.
    3. As a global variable if you want the variable to be a single instance (not unique to instances of your class) and also visible to other classes or code in other files.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Why don't you keep a hash (a JavaScript {} object)… May 12, 2026 at 12:17 am
  • Editorial Team
    Editorial Team added an answer You can add a shortcut by yourself. Tools → Options… May 12, 2026 at 12:17 am
  • Editorial Team
    Editorial Team added an answer I recall there's something called Phalanger which runs PHP on… May 12, 2026 at 12:17 am

Related Questions

Something I have found myself doing often lately is declaring typedefs relevant to a
I have a class that I've been provided that I really don't want to
To make this easier to understand, I will present the exact same problem as
I'm struggling with a T-SQL procedure and I am hoping you can help. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.