Protocols

For every object that can have a delegate, there is a corresponding protocol that declares the messages that the object can send its delegate. The delegate implements methods from the protocol for events it is interested in. When a class implements methods from a protocol, it is said to conform to the protocol.

(If you are coming from Java or C#, you would use the word interface instead of protocol.)

The protocol for UITextField’s delegate looks like this:

@protocol UITextFieldDelegate <NSObject> @optional - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; - (void)textFieldDidBeginEditing:(UITextField *)textField; - (BOOL)textFieldShouldEndEditing:(UITextField *)textField; - (void)textFieldDidEndEditing:(UITextField ...

Get iOS Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.