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

Re: Events between Objective C objects


  • Subject: Re: Events between Objective C objects
  • From: "Clark S. Cox III" <email@hidden>
  • Date: Mon, 19 May 2003 16:42:22 -0400

On Monday, May 19, 2003, at 15:55 US/Eastern, Rolf wrote:

Hi,

I'm searching for a simple straight forward way of implementing events between non-visual objects coded in Objective C. The event mechanism must be synchronous, should not involve broadcasting and does not need to support multiple listeners - one to one connections is ok. Registering

Why shouldn't it involve broadcasting (i.e. what's wrong with using NSNotifications)


for event reception (making a "connection" in Objective C terminology?) and triggering of the event must be done programatically - i.e no InterfaceBuilder. How's this done in Objective C ?
When making connections in InterfaceBuilder I see that IBAction/IBOutlet are used but I don't see the actual code that registers for event and that generates the event. How is this done programatically ?

What happens is inside the loadNib methods, it simply creates the objects described in the nib, and then searches for instance variables with the same name as the outlets in IB or instance methods with the same name as the actions in IB. Then, for outlets, it simply assigns the instance variable to point to the "connected" object, and for actions, sets the target to be the "connected" object, and the action to be the name of the action.

You could do the same thing if you really wanted:

//Setting an "outlet"
[someObject takeValue: otherObject forKey: @"outletName"];

//Setting a "target" and "action"
[someObject setTarget: otherObject];
[someObject setAction: @selector(actionName:)];


Though, using these too much could lead to some rather confusing and hard to maintain code. I would recommend using NSNotifications.



--
http://homepage.mac.com/clarkcox3/
email@hidden
Clark S. Cox, III
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Events between Objective C objects (From: Rolf <email@hidden>)

  • Prev by Date: Re: Speed Traps
  • Next by Date: Re: Where do nib files get stored in bundles???
  • Previous by thread: Events between Objective C objects
  • Next by thread: RE: Events between Objective C objects
  • Index(es):
    • Date
    • Thread