Delegation
Control events – such as .touchUpInside and .valueChanged – provide controls with a convenient, predefined list of triggers to call their action methods on their targets. But sometimes you want a control to report something that is not one of its predefined events. To have a control send a custom message to a listening object, you can use the delegation pattern.
Delegation is an object-oriented approach to callbacks. A callback is a function that is supplied in advance of an event and is called every time the event occurs. Some objects need to make a callback for more than one event. For instance, the text field needs to “call back” when the user enters text as well as when the user hits the Return key (depending on the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access