From the interface files for class_A and class_B, it seems that B is indeed not a subclass of A. They are just two classes that need to know about each other. So make sure each class has a #import directive for the other class's interface file. When you say that class A contains an instance of class B, that has nothing to do with subclassing or inheritance. If that is the case, then go ahead and write initWithParent as suggested by smasher. Although "initWithOwner" might be a more appropriate name if class A and class B do not have any subclass relationship. In your class B interface file, define an instance variable that is a pointer to an instance of class A, such as:
Class_A *myOwner;
In your initWithOwner method, set myOwner equal to the parameter that is passed by Class A. Since you are holding on to this pointer for some length of time, you should probable define it as a retained ivar and use the setter method to set it, as in:
self.myOwner = parameterPassed;
and then remember to release myOwner in your Class B dealloc method. Now whenever you want to access an instance variable of Class A from within a Class B method, just use:
myOwner.someAvariable
Robert Scott
Ypsilanti, Michigan
|