0

Say for example I have two objects A and B and that object B has a method called 'update'.

Within object A I have a line which sends the message [objectB update]. However I get the message:

error 'objectB' undeclared (first use in this function).

The thing is that objectB was declared in my Appdelegate along with objectA. Seems a bit silly that objectA cannot message objectB directly. I realise this may be some kind of scope issue but my question is really do I try to make objectA global? or do I setup a system of passing pointers back and forth making things quite messy?

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
eJm
  • 109
  • 2
  • 9
  • Let's say that you, being a good object oriented programmer, use the ObjectA class in another program. Can it assume that objectB will exist? – sosborn Nov 05 '11 at 11:18

2 Answers2

2

Take this:

[self.objectB update];

And your AppDelegate.m, you have write this:

@synthesize objectB;

I believe that it's object is private or not a getter method.

GeraldoBastos
  • 303
  • 2
  • 4
1

Since objectB is a member of app delegate, access it like this.

YourAppDelegate *appDelegate;
appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.objectB update];
EmptyStack
  • 51,274
  • 23
  • 147
  • 178