views:

565

answers:

2

I have created a variable in my App Delegate and from my first View Controller, I am saving a value to the variable (in the App Delegate).

Here is how I'm saving the value to the variable in the App Delegate:

MyAppDelegate *DelegateVar = TheValue;

NSLog(@"%@", DelegateVar); // This NSLog outputs correct value

Later in the program, in a separate ViewController, I am trying to retrieve the value from the App Delegate. I am getting values that look to be pointers...

Here is how I'm trying to retrieve the value:

MyAppDelegate *MyVar = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

NSLog(@"%@", MyVar); // outputs incorrect value

Anybody that has any input regarding my problem, your help would be greatly appreciated.

A: 

This doesn't make sense. Why are you assigning a value to a pointer to your application's delegate in the first place? If you want to assign a value to an instance variable inside your delegate, then you need to do something completely different.

Azeem.Butt
Okay... can you please give some idea about how to do this, or what might be the name of the process so that I can research it ?
Chris
Contrary to what you may have been lead to believe by many of the iPhone related books and blogs on the market, you need to actually learn C before you do anything else. None of this is going to make any sense to you until you do.
Azeem.Butt
Thank you for fighting for truth and justice.
Chris
A: 

First, you should check the main XIB file to ensure the delegate is wired up to the application.

Second, try replacing TheValue in the first instance with [[UIApplication sharedApplication]delegate] and see if you get the same incorrect value as you do later on.

John Franklin
When I switch `TheValue` with `[[UIApplication sharedApplication]delegate` , it does give me the same value `<MyAppDelegate: 0x3d1d620>` in both View Controllers - I'm guessing that value represents the address/something of the variable - so I really don't think I'm accessing it correctly the 2nd time through...
Chris
Another note, it is returning the same `<MyAppDelegate: 0x3d1d620>` every time I run the App, so I may not be accessing the data that I think I am accessing.
Chris