Re: Executing methods in one class from within another
Re: Executing methods in one class from within another
- Subject: Re: Executing methods in one class from within another
- From: Brendan Younger <email@hidden>
- Date: Wed, 12 Jun 2002 22:20:29 -0500
Ouch. Don't do this.
Either have an outlet to the other instance and connect it in IB or (if
each class only has one instance available at any specific time) create
a class method which returns the one instance in existence at any given
time. (Something like "+ (foo*)sharedInstance { if(!pointerfoo)
pointerfoo = [[foo alloc] init]; return pointerfoo; }")
If even that won't work, look into Distributed Objects. You can publish
a NSConnection under a specific name (look into
+connectionWithRegisteredName:host:) and then grab a proxy to the other
instance.
Brendan Younger
On Wednesday, June 12, 2002, at 03:51 PM, James Pengra wrote:
we have problems figuring out a way to access a method in one class
form within >another.
This is a problem that has bothered me too, and I'm wondering if my
solution is either wrong, bad practice, or just inelegant in terms of
Cocoa techniques. Here's what I do:
In each class, where desireable, I declare a global pointer to
itself. For example, between two classes "foo" and "bar".
In the file foo.m I have:
#import "foo.h"
foo *pointerfoo;
extern bar *pointerbar;
@implementation foo
// in the init method
pointerfoo = self;
// in the rest of foo class I can have such messages as
[pointerbar doSomeMethodInBar];
_________________
Then in bar.m I put:
#import "bar.h"
bar *pointerbar;
extern foo *pointerfoo;
@implementation bar
// in the init method
pointerbar = self;
// rest of bar class
___________________________
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.