• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Simple little question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple little question


  • Subject: Re: Simple little question
  • From: j o a r <email@hidden>
  • Date: Sat, 10 Sep 2005 12:34:34 +0200


On 10 sep 2005, at 12.09, Aaron Wallis wrote:

a quick question - how do I go about calling a classes parent objects method?

for example, if I have a class called human, and it has a class instanced inside it called humanArm, how/can I get humanArm to tell human something?
Is this posible?

There is no inherent parent-child relationship between an instance variable and it's "owner", so if you need to have this relationship, you need to set it up yourself, perhaps something like this:


@interface BodyPart : NSObject
{
    @private

    Body *myBody;
}

+ (id) bodyPartForBody:(Body *) aBody;
- (void) setBody:(Body *) aBody;

@end

@implementation BodyPart

+ (id) bodyPartForBody:(Body *) aBody
{
    id aBodyPart =  [[[self alloc] init] autorelease];

    [aBodyPart setBody: aBody];

    return aBodyPart;
}

- (void) setBody:(Body *) aBody
{
    // Weak reference!
    myBody = aBody;
}

@end

So, let Arm inherit from BodyPart, and when you add parts to your body, assign the body to each body part:

@implementation Body

- (void) setupBody
{
    [self addLeftArm: [Arm bodyPartForBody: self]];
    // ...and so on...
}

@end

Anyways, now you have a reference to the body in the body part, so you can access it if need be:

[myBody someMethodInTheBodyClass];


j o a r


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Simple little question (From: Aaron Wallis <email@hidden>)

  • Prev by Date: Re: create appledouble files using cocoa
  • Next by Date: Re: Tracking Rect problem.
  • Previous by thread: Simple little question
  • Next by thread: How To Design A Queue of Messages?
  • Index(es):
    • Date
    • Thread