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: James Pengra <email@hidden>
- Date: Wed, 12 Jun 2002 13:51:52 -0700
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
___________________________
As I say, this may be bad practice or inelegant, but it works for
my limited application, where both objects get instantiated by the
Nib file. I would like to know what people who understand the guts of
Objective-C think about it.
Thanks, Jim
_______________________________________________
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.