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

  • Home
  • SEARCH
  • 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 223155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:11:40+00:00 2026-05-11T19:11:40+00:00

I know this is a basic questing but I am just not finding a

  • 0

I know this is a basic questing but I am just not finding a good answer. I have a app with multiple view controllers and I have noticed that if a create a variable and take action on it in one controller:

int foo = 0;
foo =+ 1;

I can declare the variable in another controller without initializing it’s value it will carry the value it was last set to in the previous view controller:

int foo;
if (foo == 1)
    doSomething;

I have used this to my advantage for keep track of the current player in a multi player game etc… using the data in multiple controllers as their views are loaded and removed. I am new to Obj C and based on what I have been reading this does not seem like the right way to to things.

So here is my question, is this a safe way to pass data between controllers and if not what should I be doing?

  • 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-11T19:11:40+00:00Added an answer on May 11, 2026 at 7:11 pm

    This is not a safe way to be passing information between controllers. If you are using this in your application, and it’s working, I am actually very surprised.

    The proper way to do this is to actually pass the value you need from one controller to the other. The example below uses the Application Delegate to store the value, and then each controller reads/writes to it… it’s just an example, be careful about about using the Application Delegate as a repository for what become effectively global variables. Setting up lots of variables in the Application Delegate for use in this manner will make your application difficult to maintain.

    In your App Delegate.h

    @interface AppDelegate : NSObject <UIApplicationDelegate> {  
      int sharedInt;  
    }
    @property int sharedInt; 
    

    In your App Delegate.m

    @synthesize sharedInt;  // this will automatically create the getters and setters
    

    Then in the controller where you want to set the value:

    ApplicationDelegateClassNameHere * applicationDelegate = [[ UIApplication sharedApplication] delegate];  
    applicationDelegate.sharedInt = 3;
    

    Then in the controller where you want to read the value:

    ApplicationDelegateClassNameHere * applicationDelegate = [[ UIApplication sharedApplication] delegate];  
    if (applicationDelegate.sharedInt == 3) {  
       //do your stuff here
    }
    

    Edited: forgot the @synthesize.
    Edited: typed the return from the delegate singleton method, based on a suggestion from Kenneth Ballenegger, to eliminate the compiler warnings.

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

Sidebar

Related Questions

I know this maybe a basic question but I just can't seem to find
I know this maybe a very basic question but I'm having a bit of
Seems so basic, I can't believe I don't know this! I just need a
I know this isn't strictly a programming question but y'all must have experienced this.
I know this is not programming directly, but it's regarding a development workstation I'm
I know this is a basic question, but all the documentation I read doesn't
I know this is very basic question, but I need to know, how I
I know this is a pretty basic question, but I don't know how to
I know this question sounds very basic. But I can't find it using Google.
I know this is a very basic concept in Django, and I have tried

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.