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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:08:12+00:00 2026-05-22T01:08:12+00:00

I have an instance variable in my view controller that I would like to

  • 0

I have an instance variable in my view controller that I would like to share with the whole program. I’m not quite sure how to do this. Can I just declare it as a static instance variable and then access it through properties like ViewControllerClass.instancevariable?

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-05-22T01:08:13+00:00Added an answer on May 22, 2026 at 1:08 am

    In reply to your comment attached to the question:

    If you have an instance variable in Object X, any other object that has a reference to X can access that variable through the usual means:

    [objectX myClassAInstanceVariable];
    // Or, if declared with @property
    objectX.myClassAInstanceVariable;
    

    If the other object doesn’t have a reference to X, then it can’t access the variable, no matter the state or kind of the variable. In this case, you may want to rethink your design, or see my last paragraph below about the app delegate.


    The concept of “static” is different in Objective-C than what you may be expecting (it sounds like you’re coming from experience with Java).

    Objective-C doesn’t really have a concept of “class variables”, although it is fairly easy to simulate such a thing; this is described in the question that mathk linked to: Objective-C Static Class Level variables. You declare a variable in the class’s header file which is static, so that it is inaccessible outside that file, and create accessor class methods for it.

    Any object that has a reference to your view controller can send messages to it. Note that in Objective-C, member variables are “protected” by default, meaning that only an instance of a class or subclasses, not other objects, can access those variables. Other objects must go through setter and getter methods.


    Just as another option, because the background of your question is not clear, if you have some kind of a “global variable” which isn’t really specific to your view controller, a better place to put it may be the application delegate*. Any object can get a reference to the delegate at any time:

    [NSApp delegate];
    

    NSApp is a global reference to the NSApplication object which is at the core of your program.


    *Although it’s certainly possible to overdo this.

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

Sidebar

Related Questions

If you have a Property that gets and sets to an instance variable then
I have a View Controller that initializes a UIView as its view. That view
I have a form partial that looks like this: <%= form_for(@pool) do |f| %>
I have a view controller that i'm trying to push onto the navigation stack.
If I have an instance of a System.Timers.Timer that has a long interval -
I have this code working, however I don't quite understand how it is managing
I have a controller with store, model and view (toolbar) : Ext.define('Cc.controller.Headers', { extend:
I set the view controller to be the delegate of a local variable ASIHTTPFormDataRequest
I have an object which straight forward instance variables. Some are NSString, some are
I have an instance of ActiveMQ running on an externally facing server and exposing

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.