Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-29-2009, 07:31 AM   #6 (permalink)
RLScott
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,526
Default

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
RLScott is offline   Reply With Quote
 

» Advertisements
» Online Users: 769
18 members and 751 guests
apatsufas, asad, ciparis, Domele, JamesCahall, kaileymo123, karunaskj, Lanka001, lopqafezqww05, pavanindira, philipmores95, PixelInteractive, Punkjumper, rrlemoine, sarook, soonw29, twerner, vidyasagar
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,808
Threads: 89,206
Posts: 380,627
Top Poster: BrianSlick (7,129)
Welcome to our newest member, kaileymo123
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:30 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.