Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Is a delegate in Objective-C basically a class full of event listeners for an object?

0
Posted

Is a delegate in Objective-C basically a class full of event listeners for an object?

0

A delegate is merely an object that another object can use to query or customize behavior; nothing more, nothing less. No event handlers involved. It is a pattern that is used to avoid the massive tangle of subclassing that you often see in other object oriented UI kits. For example, instead of subclassing NSWindow to provide custom behavior on resize, you merely implement a few methods on a class somewhere and use an instance of that class as the delegate. Since such implementation is typically dependent on control or model layer information, it is much more natural to use a control layer class as the delegate, not subclass NSWindow, and not pollute the view layer objects with control layer functionality. Under the covers, delegates are dead simple. When resizing, an NSWindow merely asks the delegate “Do you respond to the method windowWillResize:toSize: and, if it does, calls it at the right time; nothing beyond straight objc_msgSend() about it.

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.