Re: Communication between objects
Re: Communication between objects
- Subject: Re: Communication between objects
- From: Andy Lee <email@hidden>
- Date: Wed, 11 Feb 2009 11:08:42 -0500
On Feb 11, 2009, at 10:42 AM, Jason Wiggins wrote:
But if modelObject1 doesn't know modelObject2 even exists, how can I
create a pointer to it? Where do I get this reference from?
If you want modelObject1 to have an ivar that refers to modelObject2,
the typical ways to make the connection are:
(1) modelObject1 has a setter method: [modelObject1
setObject2:modelObject2]
(2) modelObject1 has an init method that takes an argument:
modelObject1 = [[ModelObjectOne alloc] initWithObject2:modelObject2]
(3) IB outlet connection from modelObject1 to modelObject2
*Somebody* needs to know about both modelObject1 and modelObject2.
That somebody might be a third object -- perhaps even your
controller. Or it might be the nib file.
If you don't want modelObject1 to have an ivar, but only use
modelObject2 temporarily to do something, typically you pass
modelObject2 as a method argument:
[modelObject1 doSomethingWithObject2:modelObject2];
Again, something must know about both objects in order to make this
call.
BTW, it would be easier to discuss this if you would give the specific
classes you're using instead of generic placeholder names like object1
and object2. It would be easier to give advice on how to organize
your classes overall.
--Andy
aglee
_______________________________________________
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