• 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: Communication between objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Communication between objects


  • Subject: Re: Communication between objects
  • From: Ken Thomases <email@hidden>
  • Date: Wed, 11 Feb 2009 10:01:58 -0600

On Feb 11, 2009, at 9:42 AM, Jason Wiggins wrote:

Now, I understand I need a pointer to the "other object", but I am failing (in a BIG way) in understanding HOW to get it or create it.
myControllerObject has a pointer to it's children because it knows about it because it created it.
But if modelObject1 doesn't know modelObject2 even exists, how can I create a pointer to it? Where do I get this reference from?


Pseudo code...

@interface
ModelObject1 *modelObject1;
ModelObject2 *modelObject2;

@implementation
myControllerObject {

int one, two;
modelObject1 = [[ModelObject1 alloc] init];     // I now have object 1
modelObject2 = [[ModelObject2 alloc] init];     // I now have object 2

one = [modelObject1 doMethod];  // doMethod returns an int
two = [modelObject2 doMethod];  // doMethod returns an int

[modelObject1 setPartner:modelObject2];

where you have implemented a -setPartner: method on ModelObject1 which receives a pointer to a partner object, retains it, and stores it in an instance variable. Later, when the object needs to interact with its partner, it uses the pointer it stored in its instance variable.

Of course, "partner" is just a property name I made up; it's not special to the framework. Use whatever property name makes sense for your design.

Cheers,
Ken

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Communication between objects (From: Jason Wiggins <email@hidden>)
 >Re: Communication between objects (From: Clint Shryock <email@hidden>)
 >Re: Communication between objects (From: Jason Wiggins <email@hidden>)

  • Prev by Date: RE: Communication between objects
  • Next by Date: Re: Communication between objects
  • Previous by thread: Re: Communication between objects
  • Next by thread: Re: Communication between objects
  • Index(es):
    • Date
    • Thread