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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to