Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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 <em>own</em> copy of the variable, which is kept separate from all other instances of your class:</p> <pre><code>@interface AppsController : NSObject { NSMutableArray *personArray; } </code></pre> <p>Each instance of the <code>AppsController</code> class will have its own copy of the <code>personArray</code> variable, which is separate from all other instances of the class.</p> <p>If, however, you define the variable <em>outside</em> of the interface, it becomes a global variable, and it is a <em>shared</em> (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:</p> <pre><code>NSMutableArray *personArray; </code></pre> <p>it is also visible to methods in other files and classes that include your header.</p> <p>If you declare the variable in the implementation file, but outside of the implementation itself, and prefix it with the <code>static</code> 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.</p> <p>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:</p> <ol> <li>As an instance variable if your <code>personArray</code> variable needs to be <em>unique</em> 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).</li> <li>As a class variable (using the <code>static</code> keyword) if you want the variable to be visible to all instances of your class, with only one, shared instance of the variable.</li> <li>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.</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload