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

Ask A Question

Stats

  • Questions 107k
  • Answers 107k
  • 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 Ok, here's the solution to this problem. To display the… May 11, 2026 at 9:04 pm
  • Editorial Team
    Editorial Team added an answer You should read Beware of XHTML, which is an informative… May 11, 2026 at 9:04 pm
  • Editorial Team
    Editorial Team added an answer Add padding-bottom to the body element and set the margin… May 11, 2026 at 9:04 pm

Related Questions

I want a list of hyperlinks on a basic html page, which point to
I know this is a pretty basic question, and I think I know the
To teach myself Javascript, I'm trying to make a web page that gives users
This is a basic LINQ question. In my RIA Services Application, I have a
Recently, I made a post about the developers I'm working with not using try

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.